Author: Alex Date: 2011-01-25 21:52:41 -0600 (Tue, 25 Jan 2011) New Revision: 15319
Modified: django/branches/releases/1.2.X/django/db/models/sql/compiler.py django/branches/releases/1.2.X/tests/regressiontests/aggregation_regress/tests.py Log: [1.2.X] Fixed #13159 -- properly quote aggregates in order_by. Backport of [15318]. Modified: django/branches/releases/1.2.X/django/db/models/sql/compiler.py =================================================================== --- django/branches/releases/1.2.X/django/db/models/sql/compiler.py 2011-01-26 03:48:15 UTC (rev 15318) +++ django/branches/releases/1.2.X/django/db/models/sql/compiler.py 2011-01-26 03:52:41 UTC (rev 15319) @@ -327,7 +327,7 @@ 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 Modified: django/branches/releases/1.2.X/tests/regressiontests/aggregation_regress/tests.py =================================================================== --- django/branches/releases/1.2.X/tests/regressiontests/aggregation_regress/tests.py 2011-01-26 03:48:15 UTC (rev 15318) +++ django/branches/releases/1.2.X/tests/regressiontests/aggregation_regress/tests.py 2011-01-26 03:52:41 UTC (rev 15319) @@ -768,6 +768,18 @@ 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): -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.