mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 04:20:12 +03:00
Using standard assert
instead of self.fail()
.
This commit is contained in:
parent
0419a23fb8
commit
831f688cc5
|
@ -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))
|
||||
|
||||
if rounding is not None:
|
||||
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)
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user