summaryrefslogtreecommitdiff
path: root/tests/queries
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/queries
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/queries')
-rw-r--r--tests/queries/test_qs_combinators.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index 71d2418f2b..cb5ba1a269 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -1,7 +1,16 @@
import operator
from django.db import DatabaseError, NotSupportedError, connection
-from django.db.models import Exists, F, IntegerField, OuterRef, Subquery, Value
+from django.db.models import (
+ Exists,
+ F,
+ IntegerField,
+ OuterRef,
+ Subquery,
+ Transform,
+ Value,
+)
+from django.db.models.functions import Mod
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.utils import CaptureQueriesContext
@@ -322,6 +331,23 @@ class QuerySetSetOperationTests(TestCase):
operator.itemgetter("num"),
)
+ def test_order_by_annotation_transform(self):
+ class Mod2(Mod, Transform):
+ def __init__(self, expr):
+ super().__init__(expr, 2)
+
+ output_field = IntegerField()
+ output_field.register_instance_lookup(Mod2, "mod2")
+ qs1 = Number.objects.annotate(
+ annotation=Value(1, output_field=output_field),
+ )
+ qs2 = Number.objects.annotate(
+ annotation=Value(2, output_field=output_field),
+ )
+ msg = "Ordering combined queries by transforms is not implemented."
+ with self.assertRaisesMessage(NotImplementedError, msg):
+ list(qs1.union(qs2).order_by("annotation__mod2"))
+
def test_union_with_select_related_and_order(self):
e1 = ExtraInfo.objects.create(value=7, info="e1")
a1 = Author.objects.create(name="a1", num=1, extra=e1)