summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/composite_pk/test_aggregate.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/composite_pk/test_aggregate.py b/tests/composite_pk/test_aggregate.py
index d852fdce30..8a2067cb90 100644
--- a/tests/composite_pk/test_aggregate.py
+++ b/tests/composite_pk/test_aggregate.py
@@ -141,3 +141,23 @@ class CompositePKAggregateTests(TestCase):
msg = "Max expression does not support composite primary keys."
with self.assertRaisesMessage(ValueError, msg):
Comment.objects.aggregate(Max("pk"))
+
+ def test_first_from_unordered_queryset_aggregation_pk_selected(self):
+ self.assertEqual(
+ Comment.objects.values("pk").annotate(max=Max("id")).first(),
+ {"pk": (1, 1), "max": 1},
+ )
+
+ def test_first_from_unordered_queryset_aggregation_pk_selected_separately(self):
+ self.assertEqual(
+ Comment.objects.values("tenant", "id").annotate(max=Max("id")).first(),
+ {"tenant": 1, "id": 1, "max": 1},
+ )
+
+ def test_first_from_unordered_queryset_aggregation_pk_incomplete(self):
+ msg = (
+ "Cannot use QuerySet.first() on an unordered queryset performing "
+ "aggregation. Add an ordering with order_by()."
+ )
+ with self.assertRaisesMessage(TypeError, msg):
+ Comment.objects.values("tenant").annotate(max=Max("id")).first()