summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-04-10 22:26:26 +0500
committerTim Graham <timograham@gmail.com>2017-04-10 13:26:26 -0400
commite7afef13f594eb667f2709c0ef7bca98452ab32b (patch)
treef9c50366cb2a015dacaf44a70cb0e0c4f70717f6 /tests
parent64264c9a19b7dae6cd1d5e112177cdbcafafc93c (diff)
Fixed #26788 -- Fixed QuerySet.update() crash when updating a geometry to another one.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geoapp/models.py6
-rw-r--r--tests/gis_tests/geoapp/test_expressions.py30
2 files changed, 34 insertions, 2 deletions
diff --git a/tests/gis_tests/geoapp/models.py b/tests/gis_tests/geoapp/models.py
index 363f3deaf0..b555165e56 100644
--- a/tests/gis_tests/geoapp/models.py
+++ b/tests/gis_tests/geoapp/models.py
@@ -101,3 +101,9 @@ class NonConcreteField(models.IntegerField):
class NonConcreteModel(NamedModel):
non_concrete = NonConcreteField()
point = models.PointField(geography=True)
+
+
+class ManyPointModel(NamedModel):
+ point1 = models.PointField()
+ point2 = models.PointField()
+ point3 = models.PointField(srid=3857)
diff --git a/tests/gis_tests/geoapp/test_expressions.py b/tests/gis_tests/geoapp/test_expressions.py
index c18d07f0e8..72f9a37dc4 100644
--- a/tests/gis_tests/geoapp/test_expressions.py
+++ b/tests/gis_tests/geoapp/test_expressions.py
@@ -1,11 +1,12 @@
from unittest import skipUnless
-from django.contrib.gis.db.models import GeometryField, Value, functions
+from django.contrib.gis.db.models import F, GeometryField, Value, functions
from django.contrib.gis.geos import Point, Polygon
+from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
from ..utils import postgis
-from .models import City
+from .models import City, ManyPointModel
@skipUnlessDBFeature('gis_enabled')
@@ -29,3 +30,28 @@ class GeoExpressionsTests(TestCase):
p = Polygon(((1, 1), (1, 2), (2, 2), (2, 1), (1, 1)))
area = City.objects.annotate(a=functions.Area(Value(p, GeometryField(srid=4326, geography=True)))).first().a
self.assertAlmostEqual(area.sq_km, 12305.1, 0)
+
+ def test_update_from_other_field(self):
+ p1 = Point(1, 1, srid=4326)
+ p2 = Point(2, 2, srid=4326)
+ obj = ManyPointModel.objects.create(
+ point1=p1,
+ point2=p2,
+ point3=p2.transform(3857, clone=True),
+ )
+ # Updating a point to a point of the same SRID.
+ ManyPointModel.objects.filter(pk=obj.pk).update(point2=F('point1'))
+ obj.refresh_from_db()
+ self.assertEqual(obj.point2, p1)
+ # Updating a point to a point with a different SRID.
+ if connection.features.supports_transform:
+ ManyPointModel.objects.filter(pk=obj.pk).update(point3=F('point1'))
+ obj.refresh_from_db()
+ self.assertTrue(obj.point3.equals_exact(p1.transform(3857, clone=True), 0.1))
+
+ @skipUnlessDBFeature('has_Translate_function')
+ def test_update_with_expression(self):
+ city = City.objects.create(point=Point(1, 1, srid=4326))
+ City.objects.filter(pk=city.pk).update(point=functions.Translate('point', 1, 1))
+ city.refresh_from_db()
+ self.assertEqual(city.point, Point(2, 2, srid=4326))