Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Justin Bronn authored July 16, 2009
10  django/contrib/gis/db/models/sql/query.py
@@ -13,7 +13,9 @@
13 13
 ALL_TERMS = sql.constants.QUERY_TERMS.copy()
14 14
 ALL_TERMS.update(SpatialBackend.gis_terms)
15 15
 
  16
+# Pulling out other needed constants/routines to avoid attribute lookups.
16 17
 TABLE_NAME = sql.constants.TABLE_NAME
  18
+get_proxied_model = sql.query.get_proxied_model
17 19
 
18 20
 class GeoQuery(sql.Query):
19 21
     """
@@ -153,7 +155,9 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
153 155
             opts = self.model._meta
154 156
         aliases = set()
155 157
         only_load = self.deferred_to_columns()
156  
-        proxied_model = opts.proxy and opts.proxy_for_model or 0
  158
+        # Skip all proxy to the root proxied model
  159
+        proxied_model = get_proxied_model(opts)
  160
+
157 161
         if start_alias:
158 162
             seen = {None: start_alias}
159 163
         for field, model in opts.get_fields_with_model():
@@ -205,6 +209,10 @@ def resolve_columns(self, row, fields=()):
205 209
         """
206 210
         values = []
207 211
         aliases = self.extra_select.keys()
  212
+        if self.aggregates:
  213
+            # If we have an aggregate annotation, must extend the aliases
  214
+            # so their corresponding row values are included.
  215
+            aliases.extend([None for i in xrange(len(self.aggregates))])
208 216
 
209 217
         # Have to set a starting row number offset that is used for
210 218
         # determining the correct starting row index -- needed for
20  django/contrib/gis/tests/relatedapp/tests.py
@@ -231,8 +231,12 @@ def test11_geoquery_pickle(self):
231 231
         q = pickle.loads(q_str)
232 232
         self.assertEqual(GeoQuery, q.__class__)
233 233
 
234  
-    def test12_count(self):
235  
-        "Testing `Count` aggregate use with the `GeoManager`. See #11087."
  234
+    # TODO: fix on Oracle -- get the following error because the SQL is ordered
  235
+    # by a geometry object, which Oracle apparently doesn't like:
  236
+    #  ORA-22901: cannot compare nested table or VARRAY or LOB attributes of an object type
  237
+    @no_oracle
  238
+    def test12a_count(self):
  239
+        "Testing `Count` aggregate use with the `GeoManager` on geo-fields."
236 240
         # Creating a new City, 'Fort Worth', that uses the same location
237 241
         # as Dallas.
238 242
         dallas = City.objects.get(name='Dallas')
@@ -242,6 +246,8 @@ def test12_count(self):
242 246
         loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id)
243 247
         self.assertEqual(2, loc.num_cities)
244 248
 
  249
+    def test12b_count(self):
  250
+        "Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087."
245 251
         # Creating some data for the Book/Author non-geo models that
246 252
         # use GeoManager.  See #11087.
247 253
         tp = Author.objects.create(name='Trevor Paglen')
@@ -250,13 +256,19 @@ def test12_count(self):
250 256
         Book.objects.create(title='Blank Spots on the Map', author=tp)
251 257
         wp = Author.objects.create(name='William Patry')
252 258
         Book.objects.create(title='Patry on Copyright', author=wp)
253  
-        
  259
+
254 260
         # Should only be one author (Trevor Paglen) returned by this query, and
255  
-        # the annotation should have 3 for the number of books.
  261
+        # the annotation should have 3 for the number of books.  Also testing
  262
+        # with a `GeoValuesQuerySet` (see #11489).
256 263
         qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1)
  264
+        vqs = Author.objects.values('name').annotate(num_books=Count('books')).filter(num_books__gt=1)
257 265
         self.assertEqual(1, len(qs))
258 266
         self.assertEqual(3, qs[0].num_books)
  267
+        self.assertEqual(1, len(vqs))
  268
+        self.assertEqual(3, vqs[0]['num_books'])
259 269
 
  270
+    # TODO: The phantom model does appear on Oracle.
  271
+    @no_oracle
260 272
     def test13_select_related_null_fk(self):
261 273
         "Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381."
262 274
         no_author = Book.objects.create(title='Without Author')

0 notes on commit 53b8809

Please sign in to comment.
Something went wrong with that request. Please try again.