From 89f17e7caf0d1e70417253d135607c9fd6ebac56 Mon Sep 17 00:00:00 2001 From: Daniel Wiesmann Date: Mon, 15 Aug 2016 18:18:48 +0100 Subject: [PATCH] Fixed #27014 -- Fixed annotations with database functions on PostGIS. Thanks Sean Mc Allister for providing a test. --- django/contrib/gis/db/backends/postgis/adapter.py | 2 +- docs/releases/1.10.1.txt | 3 +++ tests/gis_tests/geogapp/tests.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/db/backends/postgis/adapter.py b/django/contrib/gis/db/backends/postgis/adapter.py index 2d2d9578ec..9e107db6d6 100644 --- a/django/contrib/gis/db/backends/postgis/adapter.py +++ b/django/contrib/gis/db/backends/postgis/adapter.py @@ -15,7 +15,7 @@ class PostGISAdapter(object): """ Initialize on the spatial object. """ - self.is_geometry = isinstance(obj, Geometry) + self.is_geometry = isinstance(obj, (Geometry, PostGISAdapter)) # Getting the WKB (in string form, to allow easy pickling of # the adaptor) and the SRID from the geometry or raster. diff --git a/docs/releases/1.10.1.txt b/docs/releases/1.10.1.txt index b834915701..fdc00861c6 100644 --- a/docs/releases/1.10.1.txt +++ b/docs/releases/1.10.1.txt @@ -48,3 +48,6 @@ Bugfixes * Fixed ``ClearableFileInput`` to avoid the ``required`` HTML attribute when initial data exists (:ticket:`27037`). + +* Fixed annotations with database functions when combined with lookups on + PostGIS (:ticket:`27014`). diff --git a/tests/gis_tests/geogapp/tests.py b/tests/gis_tests/geogapp/tests.py index 530b9ac4b6..f1e6de2625 100644 --- a/tests/gis_tests/geogapp/tests.py +++ b/tests/gis_tests/geogapp/tests.py @@ -142,6 +142,9 @@ class GeographyFunctionTests(TestCase): qs = Zipcode.objects.annotate(distance=Distance('poly', htown.point)) for z, ref in zip(qs, ref_dists): self.assertAlmostEqual(z.distance.m, ref, 2) + # Distance function in combination with a lookup. + hzip = Zipcode.objects.get(code='77002') + self.assertEqual(qs.get(distance__lte=0), hzip) @skipUnlessDBFeature("has_Area_function", "supports_distance_geodetic") def test_geography_area(self):