Fixed #13159 -- properly quote aggregates in order_by.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15318 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
91414c4bb8
commit
80287f1e8a
|
@ -330,7 +330,7 @@ class SQLCompiler(object):
|
||||||
continue
|
continue
|
||||||
col, order = get_order_dir(field, asc)
|
col, order = get_order_dir(field, asc)
|
||||||
if col in self.query.aggregate_select:
|
if col in self.query.aggregate_select:
|
||||||
result.append('%s %s' % (col, order))
|
result.append('%s %s' % (qn(col), order))
|
||||||
continue
|
continue
|
||||||
if '.' in field:
|
if '.' in field:
|
||||||
# This came in through an extra(order_by=...) addition. Pass it
|
# This came in through an extra(order_by=...) addition. Pass it
|
||||||
|
|
|
@ -747,6 +747,19 @@ class AggregationTests(TestCase):
|
||||||
attrgetter("name")
|
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')
|
@skipUnlessDBFeature('supports_stddev')
|
||||||
def test_stddev(self):
|
def test_stddev(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue