Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum Value Exceeded #1254

Open
Salacas opened this issue Jun 14, 2024 · 0 comments
Open

Maximum Value Exceeded #1254

Salacas opened this issue Jun 14, 2024 · 0 comments

Comments

@Salacas
Copy link

Salacas commented Jun 14, 2024

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:
Captura desde 2024-06-13 11-07-21
When we generate the schema, the default values for post (or put, patch, etc.) method are:
Captura desde 2024-06-13 11-07-54
The default value of 'depth' exceeds the limit by 1, as shown in the response:

Captura desde 2024-06-13 11-08-32

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant