#33954: "NaN" can be stored in DecimalField but cannot be retrieved
-------------------------------------+-------------------------------------
Reporter: Xabier Bello | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Neeraj Kumar):
I think **`from_float`** method will be enough for this.
{{{
def to_python(self, value):
if value is None:
return value
if isinstance(value, float):
if math.isnan(value):
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)
return self.context.create_decimal_from_float(value)
try:
return decimal.Decimal.from_float(value) # If any value that
is not floating or int, it will give TypeError, like 'nan' and 'inf' will
be TypeError for this.
except (decimal.InvalidOperation, TypeError, ValueError):
raise exceptions.ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:5>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070182d6549838-a9e857b0-9e65-4847-b88b-4a3bcb43ac29-000000%40eu-central-1.amazonses.com.