diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2021-09-29 00:00:50 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-29 20:53:16 +0200 |
| commit | b2a0978610413e4cd5ebb716b8bfa7803dff8d5b (patch) | |
| tree | 4ffaefa0f303e51266852bb8251eef28a5f8da54 /tests/annotations | |
| parent | aab76433ed585ebe997b94547e0d790605e01ad9 (diff) | |
[4.0.x] Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
Backport of dd1fa3a31b4680c0d3712e6ae122b878138580c7 from main
Diffstat (limited to 'tests/annotations')
| -rw-r--r-- | tests/annotations/tests.py | 6 |
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: |
