From b2a0978610413e4cd5ebb716b8bfa7803dff8d5b Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Wed, 29 Sep 2021 00:00:50 +0200 Subject: [4.0.x] Fixed #33018 -- Fixed annotations with empty queryset. Thanks Simon Charette for the review and implementation idea. Backport of dd1fa3a31b4680c0d3712e6ae122b878138580c7 from main --- tests/annotations/tests.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/annotations') diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index c0fe308a07..62912ee99c 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -210,6 +210,12 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertEqual(len(books), Book.objects.count()) self.assertTrue(all(not book.selected for book in books)) + def test_empty_queryset_annotation(self): + qs = Author.objects.annotate( + empty=Subquery(Author.objects.values('id').none()) + ) + self.assertIsNone(qs.first().empty) + def test_annotate_with_aggregation(self): books = Book.objects.annotate(is_book=Value(1), rating_count=Count('rating')) for book in books: -- cgit v1.3