mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
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:
parent
8f9b875456
commit
5bb7db2d6f
|
@ -1135,11 +1135,12 @@ class DecimalField(Field):
|
|||
return value
|
||||
|
||||
context = decimal.getcontext().copy()
|
||||
rounding = context.rounding if self.rounding is None else self.rounding
|
||||
if self.max_digits is not None:
|
||||
context.prec = self.max_digits
|
||||
return value.quantize(
|
||||
decimal.Decimal('.1') ** self.decimal_places,
|
||||
rounding=self.rounding,
|
||||
rounding=rounding,
|
||||
context=context
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user