Do not validate decimal precision when rounding

This commit is contained in:
Ryan P Kilby 2019-12-11 22:37:05 -08:00 committed by GitHub
parent 1a6057fd9b
commit a5328c11a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1080,10 +1080,11 @@ class DecimalField(Field):
if value in (decimal.Decimal('Inf'), decimal.Decimal('-Inf')): if value in (decimal.Decimal('Inf'), decimal.Decimal('-Inf')):
self.fail('invalid') self.fail('invalid')
if self.rounding is None: if self.rounding is not None:
# It is unnecessary to validate precision when rounding,
# since the value will be truncated to the correct size.
return self.quantize(value)
return self.quantize(self.validate_precision(value)) return self.quantize(self.validate_precision(value))
else:
return self.validate_precision(self.quantize(value))
def validate_precision(self, value): def validate_precision(self, value):
""" """