id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 7777,DecimalField validation ignores infinity and nan,Farhan Ahmad,Farhan Ahmad,"I have noticed that the DecimalField validation doesn't validate inf and nan. It does check the digits and decimals places, which could be one way to get inf, but user can enter literal 'inf' and 'nan' strings to get these special values. decimal.Decimal() doesn't raise the DecimalException in these cases because these are valid Decimal values. This validation is done in several different places. {{{ grep -Ir ""Decimal("" * | grep -v ""\.svn"" | less core/validators.py: val = Decimal(field_data) db/models/fields/__init__.py: return decimal.Decimal(value) db/backends/util.py: return decimal.Decimal(s) newforms/fields.py: value = Decimal(value) oldforms/__init__.py: v = validators.IsValidDecimal(self.max_digits, self.decimal_places) oldforms/__init__.py: return decimal.Decimal(data) }}} I noticed that pgsql can handle 'nan' value, but it doesn't handle 'inf' so I am not sure if this check is ignored intentionally or not. If this is intentional then we should add a note to the DecimalField documentation telling the users that they should account for these separately. Just as an FYI, these values can be checked by using the is_nan or is_infinite functions... {{{ #!python # Example if Decimal.is_nan(value) or Decimal.is_infinite(value): ... }}}",Uncategorized,closed,Core (Other),SVN,Normal,fixed,,farhan@…,Accepted,1,0,0,0,0,0