From c3531d2f208c5a039a190ec36a7349f627f13f01 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 7 Nov 2015 14:43:33 +0100 Subject: [PATCH] Removed ability to pass a geometry string to GIS functions This was a possible confusion source with column name arguments. Thanks Sergey Fedoseev for the suggestion. --- django/contrib/gis/db/models/functions.py | 12 ++---------- tests/gis_tests/distapp/tests.py | 4 +--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py index c222f08b1b..5b59e02f0b 100644 --- a/django/contrib/gis/db/models/functions.py +++ b/django/contrib/gis/db/models/functions.py @@ -2,7 +2,6 @@ from decimal import Decimal from django.contrib.gis.db.models.fields import GeometryField from django.contrib.gis.db.models.sql import AreaField -from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.measure import ( Area as AreaMeasure, Distance as DistanceMeasure, ) @@ -91,16 +90,9 @@ class GeomValue(Value): class GeoFuncWithGeoParam(GeoFunc): def __init__(self, expression, geom, *expressions, **extra): - if not hasattr(geom, 'srid'): - # Try to interpret it as a geometry input - try: - geom = GEOSGeometry(geom) - except Exception: - raise ValueError("This function requires a geometric parameter.") - if not geom.srid: + if not hasattr(geom, 'srid') or not geom.srid: raise ValueError("Please provide a geometry attribute with a defined SRID.") - geom = GeomValue(geom) - super(GeoFuncWithGeoParam, self).__init__(expression, geom, *expressions, **extra) + super(GeoFuncWithGeoParam, self).__init__(expression, GeomValue(geom), *expressions, **extra) class SQLiteDecimalToFloatMixin(object): diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py index 2483e852fb..c50f1124f0 100644 --- a/tests/gis_tests/distapp/tests.py +++ b/tests/gis_tests/distapp/tests.py @@ -516,9 +516,7 @@ class DistanceFunctionsTests(TestCase): dist_qs = [dist1] else: dist2 = SouthTexasCityFt.objects.annotate(distance=Distance('point', lagrange)).order_by('id') - # Using EWKT string parameter. - dist3 = SouthTexasCityFt.objects.annotate(distance=Distance('point', lagrange.ewkt)).order_by('id') - dist_qs = [dist1, dist2, dist3] + dist_qs = [dist1, dist2] # Original query done on PostGIS, have to adjust AlmostEqual tolerance # for Oracle.