Fixed #34372 -- Fixed queryset crash on order by aggregation using OrderBy.

Regression in 278881e376 caused by a lack
of expression copying when an OrderBy expression is explicitly provided.

Thanks Jannis Vajen for the report and regression test.
This commit is contained in:
Simon Charette 2023-02-27 01:10:19 -05:00 committed by GitHub
parent 2276ec8c21
commit b15f162f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -638,3 +638,9 @@ class OrderingTests(TestCase):
.first(),
self.a1,
)
def test_order_by_expr_query_reuse(self):
qs = Author.objects.annotate(num=Count("article")).order_by(
F("num").desc(), "pk"
)
self.assertCountEqual(qs, qs.iterator())