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.
* owner: nobody => Mohamed Karam
* status: new => assigned
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:6>
* stage: Accepted => Ready for checkin
Comment:
[https://github.com/django/django/pull/16002 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33954#comment:7>
* 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>