diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 8659b660b6c1..16b5c74951c0 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -123,4 +123,5 @@ class MultiPolygon(GeometryCollection): MultiPoint, MultiLineString, MultiPolygon, + GeometryCollection, ) diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py index 949cbd4ff9f5..8819328bb8c0 100644 --- a/django/db/backends/sqlite3/operations.py +++ b/django/db/backends/sqlite3/operations.py @@ -315,7 +315,10 @@ def _create_decimal(value): def get_decimalfield_converter(self, expression): # SQLite stores only 15 significant digits. Digits coming from # float inaccuracy must be removed. - if isinstance(expression, Col): + if ( + isinstance(expression, Col) + and expression.output_field.decimal_places is not None + ): quantize_value = decimal.Decimal(1).scaleb( -expression.output_field.decimal_places ) diff --git a/docs/releases/6.1.1.txt b/docs/releases/6.1.1.txt index 225b3bf07b0f..ec9affd7e790 100644 --- a/docs/releases/6.1.1.txt +++ b/docs/releases/6.1.1.txt @@ -30,3 +30,7 @@ Bugfixes changed only the Python-level ``on_delete`` option of ``ForeignKey`` or ``OneToOneField`` fields to perform unnecessary schema changes (:ticket:`37260`). + +* Fixed a bug in Django 6.1 where :class:`~django.db.models.DecimalField` + without ``max_digits`` and ``decimal_places`` caused a crash when retrieving + values on SQLite (:ticket:`37275`). diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 025e4fb4f360..a76aed6dcf63 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -1347,6 +1347,10 @@ def test_collections_of_collections(self): # And, they should be equal. self.assertEqual(gc1, gc2) + # GeometryCollections can themselves contain GeometryCollections. + gc3 = GeometryCollection(gc2) + self.assertEqual(gc1, gc3[0]) + def test_gdal(self): "Testing `ogr` and `srs` properties." g1 = fromstr("POINT(5 23)") diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index c1e356bb5318..355a58a5b132 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -35,6 +35,13 @@ class Foo(models.Model): d = models.DecimalField(max_digits=5, decimal_places=3) +class DecimalWithoutPrecision(models.Model): + value = models.DecimalField() + + class Meta: + required_db_features = {"supports_no_precision_decimalfield"} + + def get_foo(): return Foo.objects.get(id=1).pk diff --git a/tests/model_fields/test_decimalfield.py b/tests/model_fields/test_decimalfield.py index bab9a39c19d7..edf079d520a2 100644 --- a/tests/model_fields/test_decimalfield.py +++ b/tests/model_fields/test_decimalfield.py @@ -6,9 +6,9 @@ from django.core.exceptions import ValidationError from django.db import connection, models from django.db.models import Max -from django.test import TestCase +from django.test import TestCase, skipUnlessDBFeature -from .models import BigD, Foo +from .models import BigD, DecimalWithoutPrecision, Foo class DecimalFieldTests(TestCase): @@ -158,3 +158,10 @@ def test_roundtrip_integer_with_trailing_zeros(self): obj = Foo.objects.create(a="bar", d=Decimal("8")) obj.refresh_from_db() self.assertEqual(obj.d.compare_total(Decimal("8.000")), Decimal("0")) + + @skipUnlessDBFeature("supports_no_precision_decimalfield") + def test_decimalfield_without_precision(self): + value = Decimal("0.99") + obj = DecimalWithoutPrecision.objects.create(value=value) + obj.refresh_from_db() + self.assertEqual(obj.value, value)