﻿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
36233	Specific DecimalField with integer part longer than 15 digits can be stored but not retrieved on SQLite	Orazio	Samriddha Kumar Tripathi	"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? "	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	sqlite, decimalfield, invalidoperation		Ready for checkin	1	0	0	0	0	0
