Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13159 -- properly quote aggregates in order_by.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15318 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 80287f1e8a554290faa6a0c31113a9f4eecf7b79 1 parent 91414c4
Alex Gaynor authored January 26, 2011
2  django/db/models/sql/compiler.py
@@ -330,7 +330,7 @@ def get_ordering(self):
330 330
                 continue
331 331
             col, order = get_order_dir(field, asc)
332 332
             if col in self.query.aggregate_select:
333  
-                result.append('%s %s' % (col, order))
  333
+                result.append('%s %s' % (qn(col), order))
334 334
                 continue
335 335
             if '.' in field:
336 336
                 # This came in through an extra(order_by=...) addition. Pass it
13  tests/regressiontests/aggregation_regress/tests.py
@@ -747,6 +747,19 @@ def test_annotation_disjunction(self):
747 747
             attrgetter("name")
748 748
         )
749 749
 
  750
+    def test_quoting_aggregate_order_by(self):
  751
+        qs = Book.objects.filter(
  752
+            name="Python Web Development with Django"
  753
+        ).annotate(
  754
+            authorCount=Count("authors")
  755
+        ).order_by("authorCount")
  756
+        self.assertQuerysetEqual(
  757
+            qs, [
  758
+                ("Python Web Development with Django", 3),
  759
+            ],
  760
+            lambda b: (b.name, b.authorCount)
  761
+        )
  762
+
750 763
     @skipUnlessDBFeature('supports_stddev')
751 764
     def test_stddev(self):
752 765
         self.assertEqual(

0 notes on commit 80287f1

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