diff options
| author | Vinko Mlačić <vinkomlacic@outlook.com> | 2025-01-28 22:57:32 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-30 11:17:17 +0000 |
| commit | c6ace896a2da73356f7c9a655bbe32a0e3ce0435 (patch) | |
| tree | ea18520926b81251c65256951369ae5760965e0a /tests/annotations | |
| parent | b84478ae953d049a1da42c3d0ef3ab3a9467b649 (diff) | |
Fixed #36155 -- Improved error handling when annotate arguments require an alias.
Regression in ed0cbc8d8b314e3b4a0305d0be3cf366d8ee4a74.
Diffstat (limited to 'tests/annotations')
| -rw-r--r-- | tests/annotations/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 29660a827e..5df958c333 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -969,6 +969,24 @@ class NonAggregateAnnotationTestCase(TestCase): ): Book.objects.annotate(BooleanField(), Value(False), is_book=True) + def test_complex_annotations_must_have_an_alias(self): + complex_annotations = [ + F("rating") * F("price"), + Value("title"), + Case(When(pages__gte=400, then=Value("Long")), default=Value("Short")), + Subquery( + Book.objects.filter(publisher_id=OuterRef("pk")) + .order_by("-pubdate") + .values("name")[:1] + ), + Exists(Book.objects.filter(publisher_id=OuterRef("pk"))), + ] + msg = "Complex annotations require an alias" + for annotation in complex_annotations: + with self.subTest(annotation=annotation): + with self.assertRaisesMessage(TypeError, msg): + Book.objects.annotate(annotation) + def test_chaining_annotation_filter_with_m2m(self): qs = ( Author.objects.filter( |
