Skip to content

Commit 43397a8

Browse files
bizywizytomchristie
authored andcommitted
Fixed decimal snan deserialization (#7002)
* Added test case causes exception in DecimalField deserialization * Fixed NaN checking which throws exception with sNaN value
1 parent a734e58 commit 43397a8

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

rest_framework/fields.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,7 @@ def to_internal_value(self, data):
10621062
except decimal.DecimalException:
10631063
self.fail('invalid')
10641064

1065-
# Check for NaN. It is the only value that isn't equal to itself,
1066-
# so we can use this to identify NaN values.
1067-
if value != value:
1065+
if value.is_nan():
10681066
self.fail('invalid')
10691067

10701068
# Check for infinity and negative infinity.

tests/test_fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ class TestDecimalField(FieldValues):
10801080
invalid_inputs = (
10811081
('abc', ["A valid number is required."]),
10821082
(Decimal('Nan'), ["A valid number is required."]),
1083+
(Decimal('Snan'), ["A valid number is required."]),
10831084
(Decimal('Inf'), ["A valid number is required."]),
10841085
('12.345', ["Ensure that there are no more than 3 digits in total."]),
10851086
(200000000000.0, ["Ensure that there are no more than 3 digits in total."]),

0 commit comments

Comments
 (0)