diff --git a/rest_framework/fields.py b/rest_framework/fields.py index cbc8586c4..1e7981ecc 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -990,8 +990,7 @@ class DecimalField(Field): 'max_digits': _('Ensure that there are no more than {max_digits} digits in total.'), 'max_decimal_places': _('Ensure that there are no more than {max_decimal_places} decimal places.'), 'max_whole_digits': _('Ensure that there are no more than {max_whole_digits} digits before the decimal point.'), - 'max_string_length': _('String value too large.'), - 'invalid_rounding': _('Invalid rounding option {rounding}. Valid values for rounding are: {valid_roundings}') + 'max_string_length': _('String value too large.') } MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs. @@ -1028,9 +1027,10 @@ class DecimalField(Field): self.validators.append( MinValueValidator(self.min_value, message=message)) - valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')] - if rounding is not None and rounding not in valid_roundings: - self.fail('invalid_rounding', rounding=rounding, valid_roundings=valid_roundings) + if rounding is not None: + valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')] + assert rounding in valid_roundings, \ + 'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings) self.rounding = rounding def to_internal_value(self, data):