Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #13159 -- properly quote aggregates in order_by. Backpo…

…rt of [15318].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15319 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4cee764a4621c210bd1ddbc2b4b7d29c09ce8de5 1 parent 1418c21
Alex Gaynor authored January 26, 2011
2  django/db/models/sql/compiler.py
@@ -327,7 +327,7 @@ def get_ordering(self):
327 327
                 continue
328 328
             col, order = get_order_dir(field, asc)
329 329
             if col in self.query.aggregate_select:
330  
-                result.append('%s %s' % (col, order))
  330
+                result.append('%s %s' % (qn(col), order))
331 331
                 continue
332 332
             if '.' in field:
333 333
                 # This came in through an extra(order_by=...) addition. Pass it
12  tests/regressiontests/aggregation_regress/tests.py
@@ -768,6 +768,18 @@ def test_annotation_disjunction(self):
768 768
             attrgetter("name")
769 769
         )
770 770
 
  771
+    def test_quoting_aggregate_order_by(self):
  772
+        qs = Book.objects.filter(
  773
+            name="Python Web Development with Django"
  774
+        ).annotate(
  775
+            authorCount=Count("authors")
  776
+        ).order_by("authorCount")
  777
+        self.assertQuerysetEqual(
  778
+            qs, [
  779
+                ("Python Web Development with Django", 3),
  780
+            ],
  781
+            lambda b: (b.name, b.authorCount)
  782
+        )
771 783
 
772 784
     if run_stddev_tests():
773 785
         def test_stddev(self):

0 notes on commit 4cee764

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