From 5bb7db2d6f939ba0626eb606102f478a4e613647 Mon Sep 17 00:00:00 2001 From: Keith Bussell Date: Fri, 3 Aug 2018 12:42:38 -0700 Subject: [PATCH] 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()`. --- rest_framework/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 3278cf51c..d5071a1aa 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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 )