Fixed decimal snan deserialization (#7002)

* Added test case causes exception in DecimalField deserialization

* Fixed NaN checking which throws exception with sNaN value
This commit is contained in:
Sergey 2019-10-22 12:06:37 +03:00 committed by Tom Christie
parent a734e58d44
commit 43397a81ae
2 changed files with 2 additions and 3 deletions

View File

@ -1062,9 +1062,7 @@ class DecimalField(Field):
except decimal.DecimalException: except decimal.DecimalException:
self.fail('invalid') self.fail('invalid')
# Check for NaN. It is the only value that isn't equal to itself, if value.is_nan():
# so we can use this to identify NaN values.
if value != value:
self.fail('invalid') self.fail('invalid')
# Check for infinity and negative infinity. # Check for infinity and negative infinity.

View File

@ -1080,6 +1080,7 @@ class TestDecimalField(FieldValues):
invalid_inputs = ( invalid_inputs = (
('abc', ["A valid number is required."]), ('abc', ["A valid number is required."]),
(Decimal('Nan'), ["A valid number is required."]), (Decimal('Nan'), ["A valid number is required."]),
(Decimal('Snan'), ["A valid number is required."]),
(Decimal('Inf'), ["A valid number is required."]), (Decimal('Inf'), ["A valid number is required."]),
('12.345', ["Ensure that there are no more than 3 digits in total."]), ('12.345', ["Ensure that there are no more than 3 digits in total."]),
(200000000000.0, ["Ensure that there are no more than 3 digits in total."]), (200000000000.0, ["Ensure that there are no more than 3 digits in total."]),