From 831f688cc51c5846851488d374075befa1636211 Mon Sep 17 00:00:00 2001 From: Trang Tran Date: Thu, 26 Oct 2017 21:17:49 +0700 Subject: [PATCH] Using standard `assert` instead of `self.fail()`. --- rest_framework/fields.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 4da3ce735..fc0c9a444 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -992,8 +992,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. @@ -1030,9 +1029,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):