summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-09-18 18:11:37 +0200
committerClaude Paroz <claude@2xlibre.net>2014-09-18 20:00:35 +0200
commitabc11b0a33fd823ad341ab2cc113c73545eb61e6 (patch)
tree6ecc82723a5044ca4e748e11053fa46e7e9e1e5c
parent4dcfacb5b92dc06c4a351119cf501d842d46d192 (diff)
Fixed #23514 -- Prevented queries in PostGISOperations init
Thanks Mattia Procopio for the report.
-rw-r--r--django/contrib/gis/db/backends/postgis/operations.py35
-rw-r--r--tests/backends/tests.py8
2 files changed, 33 insertions, 10 deletions
diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py
index 4fae107d5e..d598d198f8 100644
--- a/django/contrib/gis/db/backends/postgis/operations.py
+++ b/django/contrib/gis/db/backends/postgis/operations.py
@@ -176,10 +176,6 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
'bboverlaps': PostGISOperator('&&'),
}
- # Native geometry type support added in PostGIS 2.0.
- if self.spatial_version >= (2, 0, 0):
- self.geometry = True
-
# Creating a dictionary lookup of all GIS terms for PostGIS.
self.gis_terms = set(['isnull'])
self.gis_terms.update(self.geometry_operators)
@@ -220,14 +216,33 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
self.union = prefix + 'Union'
self.unionagg = prefix + 'Union'
+ # Following "attributes" are properties due to the spatial_version check and
+ # to delay database access
+ @property
+ def extent3d(self):
+ if self.spatial_version >= (2, 0, 0):
+ return self.geom_func_prefix + '3DExtent'
+ else:
+ return self.geom_func_prefix + 'Extent3D'
+
+ @property
+ def length3d(self):
if self.spatial_version >= (2, 0, 0):
- self.extent3d = prefix + '3DExtent'
- self.length3d = prefix + '3DLength'
- self.perimeter3d = prefix + '3DPerimeter'
+ return self.geom_func_prefix + '3DLength'
else:
- self.extent3d = prefix + 'Extent3D'
- self.length3d = prefix + 'Length3D'
- self.perimeter3d = prefix + 'Perimeter3D'
+ return self.geom_func_prefix + 'Length3D'
+
+ @property
+ def perimeter3d(self):
+ if self.spatial_version >= (2, 0, 0):
+ return self.geom_func_prefix + '3DPerimeter'
+ else:
+ return self.geom_func_prefix + 'Perimeter3D'
+
+ @property
+ def geometry(self):
+ # Native geometry type support added in PostGIS 2.0.
+ return self.spatial_version >= (2, 0, 0)
@cached_property
def spatial_version(self):
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 89132f2a31..2ab8f680b5 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -571,6 +571,14 @@ class BackendTestCase(TestCase):
self.assertTrue(hasattr(connection.ops, 'connection'))
self.assertEqual(connection, connection.ops.connection)
+ def test_database_operations_init(self):
+ """
+ Test that DatabaseOperations initialization doesn't query the database.
+ See #17656.
+ """
+ with self.assertNumQueries(0):
+ connection.ops.__class__(connection)
+
def test_cached_db_features(self):
self.assertIn(connection.features.supports_transactions, (True, False))
self.assertIn(connection.features.supports_stddev, (True, False))