#7777: DecimalField validation ignores infinity and nan
------------------------+---------------------------------------------------
Reporter: thebitguru | Owner: nobody
Status: new | Milestone: 1.0
Component: Validators | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------+---------------------------------------------------
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):
...
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/7777>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---