You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The default value of DecimalFields in update or create methods exceeds the maximum value, given by the arguments "max_digits" and "decimal_places" in Django's DecimalField, resulting in error responses unless the values are modified by hand.
To Reproduce
We take 'depth' field in 'Earthquakes' model:
When we generate the schema, the default values for post (or put, patch, etc.) method are:
The default value of 'depth' exceeds the limit by 1, as shown in the response:
Expected behavior
Default value of 'depth' should be 1 x 10 ^ 99 (or any value between the accepted range)
I took a look at the code, and found a possible fix.
In the following file: https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/openapi.py
changed line 814 from: value = 10 ** field.max_whole_digits
to: value = 10 ** (field.max_whole_digits - 1)
That seems to resolve the problem. However, some tests failed with this change.
The text was updated successfully, but these errors were encountered:
Describe the bug
The default value of DecimalFields in update or create methods exceeds the maximum value, given by the arguments "max_digits" and "decimal_places" in Django's DecimalField, resulting in error responses unless the values are modified by hand.
To Reproduce
We take 'depth' field in 'Earthquakes' model:
When we generate the schema, the default values for post (or put, patch, etc.) method are:
The default value of 'depth' exceeds the limit by 1, as shown in the response:
Expected behavior
Default value of 'depth' should be 1 x 10 ^ 99 (or any value between the accepted range)
I took a look at the code, and found a possible fix.
In the following file:
https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/openapi.py
changed line 814 from:
value = 10 ** field.max_whole_digits
to:
value = 10 ** (field.max_whole_digits - 1)
That seems to resolve the problem. However, some tests failed with this change.
The text was updated successfully, but these errors were encountered: