Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #11489 -- `GeoQuery.resolve_columns` now recognizes annotations…

…; disabled problematic test cases on Oracle and added notes on why.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 53b8809277c40f5011a16d6e27b221e2f48f7f97 1 parent 8d48eaa
@jbronn jbronn authored
View
10 django/contrib/gis/db/models/sql/query.py
@@ -13,7 +13,9 @@
ALL_TERMS = sql.constants.QUERY_TERMS.copy()
ALL_TERMS.update(SpatialBackend.gis_terms)
+# Pulling out other needed constants/routines to avoid attribute lookups.
TABLE_NAME = sql.constants.TABLE_NAME
+get_proxied_model = sql.query.get_proxied_model
class GeoQuery(sql.Query):
"""
@@ -153,7 +155,9 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
opts = self.model._meta
aliases = set()
only_load = self.deferred_to_columns()
- proxied_model = opts.proxy and opts.proxy_for_model or 0
+ # Skip all proxy to the root proxied model
+ proxied_model = get_proxied_model(opts)
+
if start_alias:
seen = {None: start_alias}
for field, model in opts.get_fields_with_model():
@@ -205,6 +209,10 @@ def resolve_columns(self, row, fields=()):
"""
values = []
aliases = self.extra_select.keys()
+ if self.aggregates:
+ # If we have an aggregate annotation, must extend the aliases
+ # so their corresponding row values are included.
+ aliases.extend([None for i in xrange(len(self.aggregates))])
# Have to set a starting row number offset that is used for
# determining the correct starting row index -- needed for
View
20 django/contrib/gis/tests/relatedapp/tests.py
@@ -231,8 +231,12 @@ def test11_geoquery_pickle(self):
q = pickle.loads(q_str)
self.assertEqual(GeoQuery, q.__class__)
- def test12_count(self):
- "Testing `Count` aggregate use with the `GeoManager`. See #11087."
+ # TODO: fix on Oracle -- get the following error because the SQL is ordered
+ # by a geometry object, which Oracle apparently doesn't like:
+ # ORA-22901: cannot compare nested table or VARRAY or LOB attributes of an object type
+ @no_oracle
+ def test12a_count(self):
+ "Testing `Count` aggregate use with the `GeoManager` on geo-fields."
# Creating a new City, 'Fort Worth', that uses the same location
# as Dallas.
dallas = City.objects.get(name='Dallas')
@@ -242,6 +246,8 @@ def test12_count(self):
loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id)
self.assertEqual(2, loc.num_cities)
+ def test12b_count(self):
+ "Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087."
# Creating some data for the Book/Author non-geo models that
# use GeoManager. See #11087.
tp = Author.objects.create(name='Trevor Paglen')
@@ -250,13 +256,19 @@ def test12_count(self):
Book.objects.create(title='Blank Spots on the Map', author=tp)
wp = Author.objects.create(name='William Patry')
Book.objects.create(title='Patry on Copyright', author=wp)
-
+
# Should only be one author (Trevor Paglen) returned by this query, and
- # the annotation should have 3 for the number of books.
+ # the annotation should have 3 for the number of books. Also testing
+ # with a `GeoValuesQuerySet` (see #11489).
qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1)
+ vqs = Author.objects.values('name').annotate(num_books=Count('books')).filter(num_books__gt=1)
self.assertEqual(1, len(qs))
self.assertEqual(3, qs[0].num_books)
+ self.assertEqual(1, len(vqs))
+ self.assertEqual(3, vqs[0]['num_books'])
+ # TODO: The phantom model does appear on Oracle.
+ @no_oracle
def test13_select_related_null_fk(self):
"Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
no_author = Book.objects.create(title='Without Author')
Please sign in to comment.
Something went wrong with that request. Please try again.