Permalink
Browse files

[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...
1 parent 1418c21 commit 4cee764a4621c210bd1ddbc2b4b7d29c09ce8de5 @alex alex committed Jan 26, 2011
Showing with 13 additions and 1 deletion.
  1. +1 −1 django/db/models/sql/compiler.py
  2. +12 −0 tests/regressiontests/aggregation_regress/tests.py
@@ -327,7 +327,7 @@ def get_ordering(self):
continue
col, order = get_order_dir(field, asc)
if col in self.query.aggregate_select:
- result.append('%s %s' % (col, order))
+ result.append('%s %s' % (qn(col), order))
continue
if '.' in field:
# This came in through an extra(order_by=...) addition. Pass it
@@ -768,6 +768,18 @@ def test_annotation_disjunction(self):
attrgetter("name")
)
+ def test_quoting_aggregate_order_by(self):
+ qs = Book.objects.filter(
+ name="Python Web Development with Django"
+ ).annotate(
+ authorCount=Count("authors")
+ ).order_by("authorCount")
+ self.assertQuerysetEqual(
+ qs, [
+ ("Python Web Development with Django", 3),
+ ],
+ lambda b: (b.name, b.authorCount)
+ )
if run_stddev_tests():
def test_stddev(self):

0 comments on commit 4cee764

Please sign in to comment.