﻿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
33954	"""NaN"" can be stored in DecimalField but cannot be retrieved"	Xabier Bello	Mohamed Karam	"Same as ticket https://code.djangoproject.com/ticket/33033, but I managed to trigger it anyway:

== Steps to reproduce

* Create a brand new project using python 3.10 and django 4.1 with the default sqlite3 backend.

* Create a model with a DecimalField: 
{{{
    class MyModel(models.Model):
        value = models.DecimalField(max_digits=10, decimal_places=5)
}}}
* Programmatically create a model instance with value=""nan"",
{{{
    obj = MyModel.objects.create(value=""nan"")
    obj.save()
}}}
* Then try to retrieve the object from the database (or refresh from database):
{{{
    MyModel.objects.get(pk=1)
}}}

== Traceback
{{{
    Traceback (most recent call last):
      File ""/sandbox/dj/bug/dec/views.py"", line 9, in <module>
        MyModel.objects.get(pk=1)
      File ""/lib64/python3.10/site-packages/django/db/models/manager.py"", line 85, in manager_method
        return getattr(self.get_queryset(), name)(*args, **kwargs)
      File ""/lib64/python3.10/site-packages/django/db/models/query.py"", line 646, in get
        num = len(clone)
      File ""/lib64/python3.10/site-packages/django/db/models/query.py"", line 376, in __len__
        self._fetch_all()
      File ""/lib64/python3.10/site-packages/django/db/models/query.py"", line 1866, in _fetch_all
        self._result_cache = list(self._iterable_class(self))
      File ""/lib64/python3.10/site-packages/django/db/models/query.py"", line 117, in __iter__
        for row in compiler.results_iter(results):
      File ""/lib64/python3.10/site-packages/django/db/models/sql/compiler.py"", line 1333, in apply_converters
        value = converter(value, expression, connection)
      File ""/lib64/python3.10/site-packages/django/db/backends/sqlite3/operations.py"", line 344, in converter
        return create_decimal(value).quantize(
    TypeError: argument must be int or float
}}}
The value ""nan"" (and maybe ""inf"" also) skip the validation in `DecimalField.to_python`, because is not `None`, and is not instance of float. But `decimal.Decimal(""nan"")` works without triggering the exception, so `NaN` gets stored in the DB.

"	Cleanup/optimization	closed	Database layer (models, ORM)	4.1	Normal	fixed			Ready for checkin	1	0	0	0	0	0
