1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #34590 -- Reverted "Refs #33308 -- Improved adapting DecimalField values to decimal."

This reverts 7990d254b0.

Thanks Marc Odermatt for the report.
This commit is contained in:
David Sanders 2023-05-24 18:59:55 +10:00 committed by GitHub
parent 8b053c1e3c
commit 0c1518ee42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -1810,13 +1810,11 @@ class DecimalField(Field):
)
return decimal_value
def get_db_prep_value(self, value, connection, prepared=False):
if not prepared:
value = self.get_prep_value(value)
def get_db_prep_save(self, value, connection):
if hasattr(value, "as_sql"):
return value
return connection.ops.adapt_decimalfield_value(
value, self.max_digits, self.decimal_places
self.to_python(value), self.max_digits, self.decimal_places
)
def get_prep_value(self, value):

View File

@ -36,3 +36,7 @@ Bugfixes
* Fixed a regression in Django 4.2 that caused a crash of
``QuerySet.aggregate()`` with aggregates referencing subqueries
(:ticket:`34551`).
* Fixed a regression in Django 4.2 that caused a crash of querysets on SQLite
when filtering on ``DecimalField`` against values outside of the defined
range (:ticket:`34590`).

View File

@ -91,7 +91,10 @@ class DecimalFieldTests(TestCase):
Really big values can be used in a filter statement.
"""
# This should not crash.
Foo.objects.filter(d__gte=100000000000)
self.assertSequenceEqual(Foo.objects.filter(d__gte=100000000000), [])
def test_lookup_decimal_larger_than_max_digits(self):
self.assertSequenceEqual(Foo.objects.filter(d__lte=Decimal("123456")), [])
def test_max_digits_validation(self):
field = models.DecimalField(max_digits=2)