Re: [Django] #33954: "NaN" can be stored in DecimalField but cannot be retrieved

14 views
Skip to first unread message

Django

unread,
Aug 25, 2022, 2:47:27 PM8/25/22
to django-...@googlegroups.com
#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.

Django

unread,
Aug 26, 2022, 9:04:58 AM8/26/22
to django-...@googlegroups.com
#33954: "NaN" can be stored in DecimalField but cannot be retrieved
-------------------------------------+-------------------------------------
Reporter: Xabier Bello | Owner: Mohamed
Type: | Karam
Cleanup/optimization | Status: assigned

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
-------------------------------------+-------------------------------------
Changes (by Mohamed Karam):

* owner: nobody => Mohamed Karam
* status: new => assigned

Django

unread,
Aug 26, 2022, 9:21:07 AM8/26/22
to django-...@googlegroups.com
#33954: "NaN" can be stored in DecimalField but cannot be retrieved
-------------------------------------+-------------------------------------
Reporter: Xabier Bello | Owner: Mohamed
Type: | Karam
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mohamed Karam):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:6>

Django

unread,
Aug 27, 2022, 9:59:18 AM8/27/22
to django-...@googlegroups.com
#33954: "NaN" can be stored in DecimalField but cannot be retrieved
-------------------------------------+-------------------------------------
Reporter: Xabier Bello | Owner: Mohamed
Type: | Karam
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/16002 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:7>

Django

unread,
Aug 27, 2022, 10:24:21 AM8/27/22
to django-...@googlegroups.com
#33954: "NaN" can be stored in DecimalField but cannot be retrieved
-------------------------------------+-------------------------------------
Reporter: Xabier Bello | Owner: Mohamed
Type: | Karam
Cleanup/optimization | Status: closed

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"b92ffebb0cdc469baaf1b8f0e72dddb069eb2fb4" b92ffebb]:
{{{
#!CommitTicketReference repository=""
revision="b92ffebb0cdc469baaf1b8f0e72dddb069eb2fb4"
Fixed #33954 -- Prevented models.DecimalField from accepting NaN, Inf, and
-Inf values.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:8>

Reply all
Reply to author
Forward
0 new messages