Always pass a valid rounding value

Fixes #6015

Prevent an exception in `quantize()` when monkey-patching the decimal
library as cdecimal in Python 2 environments by always passing a valid
(not None) `rounding` value to `quantize()`.
This commit is contained in:
Keith Bussell 2018-08-03 12:42:38 -07:00
parent 8f9b875456
commit 5bb7db2d6f

View File

@ -1135,11 +1135,12 @@ class DecimalField(Field):
return value return value
context = decimal.getcontext().copy() context = decimal.getcontext().copy()
rounding = context.rounding if self.rounding is None else self.rounding
if self.max_digits is not None: if self.max_digits is not None:
context.prec = self.max_digits context.prec = self.max_digits
return value.quantize( return value.quantize(
decimal.Decimal('.1') ** self.decimal_places, decimal.Decimal('.1') ** self.decimal_places,
rounding=self.rounding, rounding=rounding,
context=context context=context
) )