summaryrefslogtreecommitdiff
path: root/tests/annotations
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2021-09-29 00:00:50 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-29 20:23:29 +0200
commitdd1fa3a31b4680c0d3712e6ae122b878138580c7 (patch)
tree10205352e74cd3708581c7c262d25840be6aa12a /tests/annotations
parentad36a198a12df4dff65992191b3eb0a474e2daac (diff)
downloaddjango-dd1fa3a31b4680c0d3712e6ae122b878138580c7.tar.gz
Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
Diffstat (limited to 'tests/annotations')
-rw-r--r--tests/annotations/tests.py6
1 files changed, 6 insertions, 0 deletions
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: