Commit 4cee764a authored by Alex Gaynor's avatar Alex Gaynor
Browse files

[1.2.X] Fixed #13159 -- properly quote aggregates in order_by. Backport of [15318].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15319 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 1418c215
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ class SQLCompiler(object):
                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
+12 −0
Original line number Diff line number Diff line
@@ -768,6 +768,18 @@ class AggregationTests(TestCase):
            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):