summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2022-06-21 09:53:44 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-21 10:32:34 +0200
commit42e4b0e608fb439ca98756546bbda1152f64c8b1 (patch)
tree3811873e2789a2d188aeab83d0dd701fbf44cc2c
parent91b365ef67c82d790dc6021882d39f7aed960a2e (diff)
[4.1.x] Fixed #33794 -- Fixed string-casting of GIS queries on PostgreSQL.
Regression in 64c3f049ea3bcb1c82f35ae09f1dd5349a826a5c. Backport of de74a74b4b889c986cabab837bb03e2113880afe from main
-rw-r--r--django/contrib/gis/db/backends/postgis/adapter.py2
-rw-r--r--tests/gis_tests/geoapp/tests.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/gis/db/backends/postgis/adapter.py b/django/contrib/gis/db/backends/postgis/adapter.py
index 0e02427811..20b0327d5c 100644
--- a/django/contrib/gis/db/backends/postgis/adapter.py
+++ b/django/contrib/gis/db/backends/postgis/adapter.py
@@ -42,7 +42,7 @@ class PostGISAdapter:
return hash(self.ewkb)
def __str__(self):
- return self.getquoted()
+ return self.getquoted().decode()
@classmethod
def _fix_polygon(cls, poly):
diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py
index 0a71639c84..fd5fc3c793 100644
--- a/tests/gis_tests/geoapp/tests.py
+++ b/tests/gis_tests/geoapp/tests.py
@@ -212,6 +212,14 @@ class GeoModelTest(TestCase):
with self.assertNumQueries(0): # Ensure point isn't deferred.
self.assertIsInstance(cities2[0].point, Point)
+ def test_gis_query_as_string(self):
+ """GIS queries can be represented as strings."""
+ query = City.objects.filter(point__within=Polygon.from_bbox((0, 0, 2, 2)))
+ self.assertIn(
+ connection.ops.quote_name(City._meta.db_table),
+ str(query.query),
+ )
+
def test_dumpdata_loaddata_cycle(self):
"""
Test a dumpdata/loaddata cycle with geographic data.