summaryrefslogtreecommitdiff
path: root/tests/aggregation
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-12-08 02:03:14 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-12 05:51:33 +0100
commitb0ad41198b3e333f57351e3fce5a1fb47f23f376 (patch)
treeb68005963b6261679db534b102d4327b584d12e2 /tests/aggregation
parentfcf95e592774a6ededec35481a2061474d467a2b (diff)
Fixed #34013 -- Added QuerySet.order_by() support for annotation transforms.
Thanks Eugene Morozov and Ben Nace for the reports.
Diffstat (limited to 'tests/aggregation')
-rw-r--r--tests/aggregation/tests.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index b01df88109..bedc2730a2 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -25,6 +25,7 @@ from django.db.models import (
Subquery,
Sum,
TimeField,
+ Transform,
Value,
Variance,
When,
@@ -1727,6 +1728,28 @@ class AggregateTestCase(TestCase):
ordered=False,
)
+ def test_order_by_aggregate_transform(self):
+ class Mod100(Mod, Transform):
+ def __init__(self, expr):
+ super().__init__(expr, 100)
+
+ sum_field = IntegerField()
+ sum_field.register_instance_lookup(Mod100, "mod100")
+ publisher_pages = (
+ Book.objects.values("publisher")
+ .annotate(sum_pages=Sum("pages", output_field=sum_field))
+ .order_by("sum_pages__mod100")
+ )
+ self.assertQuerySetEqual(
+ publisher_pages,
+ [
+ {"publisher": self.p2.id, "sum_pages": 528},
+ {"publisher": self.p4.id, "sum_pages": 946},
+ {"publisher": self.p1.id, "sum_pages": 747},
+ {"publisher": self.p3.id, "sum_pages": 1482},
+ ],
+ )
+
def test_empty_result_optimization(self):
with self.assertNumQueries(0):
self.assertEqual(