From bd8afb18940b3e4f711b714dd20abf1053e31e70 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 14 Apr 2009 19:14:32 +0000 Subject: [PATCH] Fixed #10807 - `GeoWhereNode` no longer passes `Constraint` objects to where they shouldn't go. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10559 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/db/models/sql/where.py | 7 ++++--- django/contrib/gis/tests/relatedapp/tests.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/django/contrib/gis/db/models/sql/where.py b/django/contrib/gis/db/models/sql/where.py index 61c01d2902..ff6f45816c 100644 --- a/django/contrib/gis/db/models/sql/where.py +++ b/django/contrib/gis/db/models/sql/where.py @@ -76,17 +76,18 @@ class GeoWhereNode(WhereNode): # the `get_geo_where_clause` to construct the appropriate # spatial SQL when `make_atom` is called. annotation = GeoAnnotation(field, value, where) - return super(WhereNode, self).add((obj, lookup_type, annotation, params), connector) + return super(WhereNode, self).add(((alias, col, field.db_type()), lookup_type, annotation, params), connector) def make_atom(self, child, qn): - lvalue, lookup_type, value_annot, params = child + obj, lookup_type, value_annot, params = child if isinstance(value_annot, GeoAnnotation): if lookup_type in SpatialBackend.gis_terms: # Getting the geographic where clause; substitution parameters # will be populated in the GeoFieldSQL object returned by the # GeometryField. - gwc = get_geo_where_clause(lvalue.alias, lvalue.col, lookup_type, value_annot) + alias, col, db_type = obj + gwc = get_geo_where_clause(alias, col, lookup_type, value_annot) return gwc % value_annot.where, params else: raise TypeError('Invalid lookup type: %r' % lookup_type) diff --git a/django/contrib/gis/tests/relatedapp/tests.py b/django/contrib/gis/tests/relatedapp/tests.py index 703846a28d..7df2cc2b3d 100644 --- a/django/contrib/gis/tests/relatedapp/tests.py +++ b/django/contrib/gis/tests/relatedapp/tests.py @@ -210,6 +210,18 @@ class RelatedGeoModelTest(unittest.TestCase): self.assertEqual(val_dict['id'], c_id) self.assertEqual(val_dict['location__id'], l_id) + def test10_combine(self): + "Testing the combination of two GeoQuerySets. See #10807." + buf1 = City.objects.get(name='Aurora').location.point.buffer(0.1) + buf2 = City.objects.get(name='Kecksburg').location.point.buffer(0.1) + qs1 = City.objects.filter(location__point__within=buf1) + qs2 = City.objects.filter(location__point__within=buf2) + combined = qs1 | qs2 + names = [c.name for c in combined] + self.assertEqual(2, len(names)) + self.failUnless('Aurora' in names) + self.failUnless('Kecksburg' in names) + # TODO: Related tests for KML, GML, and distance lookups. def suite():