@@ -283,6 +283,11 @@ def validate(self, value):
283
283
super (DecimalField , self ).validate (value )
284
284
if value in validators .EMPTY_VALUES :
285
285
return
286
+ # Check for NaN, Inf and -Inf values. We can't compare directly for NaN,
287
+ # since it is never equal to itself. However, NaN is the only value that
288
+ # isn't equal to itself, so we can use this to identify NaN
289
+ if value != value or value == Decimal ("Inf" ) or value == Decimal ("-Inf" ):
290
+ raise ValidationError (self .error_messages ['invalid' ])
286
291
sign , digittuple , exponent = value .as_tuple ()
287
292
decimals = abs (exponent )
288
293
# digittuple doesn't include any leading zeros.
@@ -467,7 +472,7 @@ def to_python(self, data):
467
472
f = super (ImageField , self ).to_python (data )
468
473
if f is None :
469
474
return None
470
-
475
+
471
476
# Try to import PIL in either of the two ways it can end up installed.
472
477
try :
473
478
from PIL import Image
@@ -584,7 +589,7 @@ class ChoiceField(Field):
584
589
585
590
def __init__ (self , choices = (), required = True , widget = None , label = None ,
586
591
initial = None , help_text = None , * args , ** kwargs ):
587
- super (ChoiceField , self ).__init__ (required = required , widget = widget , label = label ,
592
+ super (ChoiceField , self ).__init__ (required = required , widget = widget , label = label ,
588
593
initial = initial , help_text = help_text , * args , ** kwargs )
589
594
self .choices = choices
590
595
0 commit comments