1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #33018 -- Fixed annotations with empty queryset.

Thanks Simon Charette for the review and implementation idea.
This commit is contained in:
David Wobrock
2021-09-29 00:00:50 +02:00
committed by Mariusz Felisiak
parent ad36a198a1
commit dd1fa3a31b
5 changed files with 33 additions and 4 deletions

View File

@@ -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: