#36233: Specific DecimalField with max_digits > 15 can be stored but not retrieved
on SQLite
-------------------------------------+-------------------------------------
Reporter: Orazio | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: dev | Severity: Normal
Keywords: sqlite, orm, | Triage Stage:
decimalfield, invalidoperation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Similar to
https://code.djangoproject.com/ticket/33954 but different
exception:
Given this model
{{{
class Apple(models.Model):
weight = models.DecimalField(max_digits=16, decimal_places=0)
}}}
Trying to store 9999999999999999 (16 digits)
{{{
$ python manage.py shell
7 objects imported automatically (use -v 2 for details).
Python 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> test = Apple(weight="9999999999999999")
>>> test.full_clean()
>>> test.save()
>>> Apple.objects.last()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/test_project/django/django/db/models/manager.py", line
87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/test_project/django/django/db/models/query.py", line
1105, in last
for obj in queryset[:1]:
File "/home/user/test_project/django/django/db/models/query.py", line
383, in __iter__
self._fetch_all()
File "/home/user/test_project/django/django/db/models/query.py", line
1923, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/test_project/django/django/db/models/query.py", line
122, in __iter__
for row in compiler.results_iter(results):
File "/home/user/test_project/django/django/db/models/sql/compiler.py",
line 1540, in apply_converters
value = converter(value, expression, connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/user/test_project/django/django/db/backends/sqlite3/operations.py",
line 346, in converter
return create_decimal(value).quantize(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
>>>
}}}
I made sure to test with the latest commit
{{{
$ pip list
Package Version Editable project location
-------- --------------------- -------------------------
asgiref 3.8.1
Django 6.0.dev20250306010223 /home/user/test_project/django
pip 24.0
sqlparse 0.5.3
}}}
Exception is raised here:
https://github.com/django/django/blob/bad1a18ff28a671f2fdfd447bdf8f43602f882c2/django/db/backends/sqlite3/operations.py#L346
As you might imagine this also fails when say max_digits is 20 and storing
20 nines, and so on. Shouldn't this raise an error when running
full_clean() on the object before storing?
--
Ticket URL: <
https://code.djangoproject.com/ticket/36233>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.