Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions django/contrib/gis/geos/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ class MultiPolygon(GeometryCollection):
MultiPoint,
MultiLineString,
MultiPolygon,
GeometryCollection,
)
5 changes: 4 additions & 1 deletion django/db/backends/sqlite3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/6.1.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
4 changes: 4 additions & 0 deletions tests/gis_tests/geos_tests/test_geos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
7 changes: 7 additions & 0 deletions tests/model_fields/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions tests/model_fields/test_decimalfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Loading