-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Steps to reproduce
- Create a DecimalField inside a serializer with max_value, min_value, and decimal_places set, but set max_digits = None. EG: serializers.DecimalField(max_value=100, min_value=0, decimal_places=10, max_digits=None)
- call serializer.is_valid()
- observe traceback similar to the following :
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_valid
serializer.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_value
value = 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_value
value = 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.