Author: Alex Date: 2011-01-25 21:48:15 -0600 (Tue, 25 Jan 2011) New Revision: 15318
Modified: django/trunk/django/db/models/sql/compiler.py django/trunk/tests/regressiontests/aggregation_regress/tests.py Log: Fixed #13159 -- properly quote aggregates in order_by. Modified: django/trunk/django/db/models/sql/compiler.py =================================================================== --- django/trunk/django/db/models/sql/compiler.py 2011-01-26 03:42:31 UTC (rev 15317) +++ django/trunk/django/db/models/sql/compiler.py 2011-01-26 03:48:15 UTC (rev 15318) @@ -330,7 +330,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/trunk/tests/regressiontests/aggregation_regress/tests.py =================================================================== --- django/trunk/tests/regressiontests/aggregation_regress/tests.py 2011-01-26 03:42:31 UTC (rev 15317) +++ django/trunk/tests/regressiontests/aggregation_regress/tests.py 2011-01-26 03:48:15 UTC (rev 15318) @@ -747,6 +747,19 @@ 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) + ) + @skipUnlessDBFeature('supports_stddev') def test_stddev(self): self.assertEqual( -- 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.