-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
DecimalField fails when max_digits=None
#4372
Comments
Nop. What I'd be willing to do here would be:
Closing this issue meanwhile as we're not making |
That makes sense, yeah assert when max_digits is None would be great. On Aug 9, 2016 11:53 PM, "Xavier Ordoquy" [email protected] wrote:
|
Taking a look through the code it's not clear if |
@tomchristie |
Passing the argument is required, but it may be None. |
max_digits=None
I don't think it worked before as there are other calls to quantize anyway. |
Comes across as a regression to me, tho yes slightly borderline behavior, but not massivly. Test looks happy now. |
From my tests and the source, it seems Also, it'd be cool if the docs stated exactly what happens when either of them is None. |
Steps to reproduce
Traceback (most recent call last):
File "
/api/views.py", line 263, in monitor/env/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 213, in is_validserializer.is_valid()
File "
self._validated_data = self.run_validation(self.initial_data)
File "
/env/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 407, in run_validation/env/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 437, in to_internal_valuevalue = self.to_internal_value(data)
File "
validated_value = field.run_validation(primitive_value)
File "
/env/local/lib/python2.7/site-packages/rest_framework/fields.py", line 488, in run_validation/env/local/lib/python2.7/site-packages/rest_framework/fields.py", line 959, in to_internal_valuevalue = self.to_internal_value(data)
File "
return self.quantize(self.validate_precision(value))
File "~/env/local/lib/python2.7/site-packages/rest_framework/fields.py", line 1022, in quantize
context=context
File "/usr/lib/python2.7/decimal.py", line 2455, in quantize
if not (context.Etiny() <= exp._exp <= context.Emax):
File "/usr/lib/python2.7/decimal.py", line 3898, in Etiny
return int(self.Emin - self.prec + 1)
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
Expected behavior
is_valid returns true if the value is between min and max, without concerning itself with the number of digits / precision of the number, OR do not accept None as a valid value for max_digits.
Actual behavior
an exception is raised, which is difficult to track down and counter intuitive.
The text was updated successfully, but these errors were encountered: