Skip to content

Commit bfc1638

Browse files
committed
FloatField will crash if the input is a number that is too big
1 parent 5ea9734 commit bfc1638

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

rest_framework/fields.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def get_attribute(instance, attrs):
104104
# If we raised an Attribute or KeyError here it'd get treated
105105
# as an omitted field in `Field.get_attribute()`. Instead we
106106
# raise a ValueError to ensure the exception is not masked.
107-
raise ValueError(
108-
'Exception raised in callable attribute "{}"; original exception was: {}'.format(attr, exc))
107+
raise ValueError('Exception raised in callable attribute "{}"; original exception was: {}'.format(attr, exc))
109108

110109
return instance
111110

@@ -182,7 +181,6 @@ def iter_options(grouped_choices, cutoff=None, cutoff_text=None):
182181
"""
183182
Helper function for options and option groups in templates.
184183
"""
185-
186184
class StartOptionGroup:
187185
start_option_group = True
188186
end_option_group = False
@@ -368,10 +366,10 @@ def bind(self, field_name, parent):
368366
# 'source' argument has been used. For example:
369367
# my_field = serializer.CharField(source='my_field')
370368
assert self.source != field_name, (
371-
"It is redundant to specify `source='%s'` on field '%s' in "
372-
"serializer '%s', because it is the same as the field name. "
373-
"Remove the `source` keyword argument." %
374-
(field_name, self.__class__.__name__, parent.__class__.__name__)
369+
"It is redundant to specify `source='%s'` on field '%s' in "
370+
"serializer '%s', because it is the same as the field name. "
371+
"Remove the `source` keyword argument." %
372+
(field_name, self.__class__.__name__, parent.__class__.__name__)
375373
)
376374

377375
self.field_name = field_name
@@ -796,8 +794,7 @@ def __init__(self, allow_unicode=False, **kwargs):
796794
super().__init__(**kwargs)
797795
self.allow_unicode = allow_unicode
798796
if self.allow_unicode:
799-
validator = RegexValidator(re.compile(r'^[-\w]+\Z', re.UNICODE),
800-
message=self.error_messages['invalid_unicode'])
797+
validator = RegexValidator(re.compile(r'^[-\w]+\Z', re.UNICODE), message=self.error_messages['invalid_unicode'])
801798
else:
802799
validator = RegexValidator(re.compile(r'^[-a-zA-Z0-9_]+$'), message=self.error_messages['invalid'])
803800
self.validators.append(validator)
@@ -997,7 +994,7 @@ def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=
997994
if rounding is not None:
998995
valid_roundings = [v for k, v in vars(decimal).items() if k.startswith('ROUND_')]
999996
assert rounding in valid_roundings, (
1000-
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings))
997+
'Invalid rounding option %s. Valid values for rounding are: %s' % (rounding, valid_roundings))
1001998
self.rounding = rounding
1002999

10031000
def validate_empty_values(self, data):
@@ -1735,7 +1732,6 @@ def __new__(cls, value):
17351732
ret = str.__new__(cls, value)
17361733
ret.is_json_string = True
17371734
return ret
1738-
17391735
return JSONString(dictionary[self.field_name])
17401736
return dictionary.get(self.field_name, empty)
17411737

@@ -1789,7 +1785,6 @@ class HiddenField(Field):
17891785
constraint on a pair of fields, as we need some way to include the date in
17901786
the validated data.
17911787
"""
1792-
17931788
def __init__(self, **kwargs):
17941789
assert 'default' in kwargs, 'default is a required argument.'
17951790
kwargs['write_only'] = True
@@ -1819,7 +1814,6 @@ class ExampleSerializer(Serializer):
18191814
def get_extra_info(self, obj):
18201815
return ... # Calculate some data to return.
18211816
"""
1822-
18231817
def __init__(self, method_name=None, **kwargs):
18241818
self.method_name = method_name
18251819
kwargs['source'] = '*'

0 commit comments

Comments
 (0)