From c886f3dee33adc9f94332b4133a37960e985e273 Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Wed, 10 Jan 2018 19:06:47 -0500 Subject: [PATCH] Fixed #29006 -- Fixed DecimalField.clean() crash on sNaN values. --- django/forms/fields.py | 2 +- tests/forms_tests/field_tests/test_decimalfield.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index 3b15c1b021..f161c9ed17 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -351,7 +351,7 @@ class DecimalField(IntegerField): super().validate(value) if value in self.empty_values: return - if not math.isfinite(value): + if value.is_nan() or not math.isfinite(value): raise ValidationError(self.error_messages['invalid'], code='invalid') def widget_attrs(self, widget): diff --git a/tests/forms_tests/field_tests/test_decimalfield.py b/tests/forms_tests/field_tests/test_decimalfield.py index 35a404608c..4e1828d53d 100644 --- a/tests/forms_tests/field_tests/test_decimalfield.py +++ b/tests/forms_tests/field_tests/test_decimalfield.py @@ -51,6 +51,7 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase): f = DecimalField(max_digits=4, decimal_places=2) values = ( '-NaN', 'NaN', '+NaN', + '-sNaN', 'sNaN', '+sNaN', '-Inf', 'Inf', '+Inf', '-Infinity', 'Infinity', '+Infinity', 'a', 'łąść', '1.0a', '--0.12',