diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2021-12-19 11:22:30 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-21 06:17:04 +0100 |
| commit | 72b23c04d806adc8522fa9d10132e5c1d1011d5e (patch) | |
| tree | 78c3a5b9b7f98638b1138d9556b2d689e040e15f /tests | |
| parent | 03cadb912c78b769d6bf4a943a2a35fc1d952960 (diff) | |
Fixed #33374 -- Fixed ExpressionWrapper annotations with full queryset.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/annotations/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 62912ee99c..2c2b946835 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -210,6 +210,26 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertEqual(len(books), Book.objects.count()) self.assertTrue(all(not book.selected for book in books)) + def test_full_expression_annotation(self): + books = Book.objects.annotate( + selected=ExpressionWrapper(~Q(pk__in=[]), output_field=BooleanField()), + ) + self.assertEqual(len(books), Book.objects.count()) + self.assertTrue(all(book.selected for book in books)) + + def test_full_expression_annotation_with_aggregation(self): + qs = Book.objects.filter(isbn='159059725').annotate( + selected=ExpressionWrapper(~Q(pk__in=[]), output_field=BooleanField()), + rating_count=Count('rating'), + ) + self.assertEqual([book.rating_count for book in qs], [1]) + + def test_aggregate_over_full_expression_annotation(self): + qs = Book.objects.annotate( + selected=ExpressionWrapper(~Q(pk__in=[]), output_field=BooleanField()), + ).aggregate(Sum('selected')) + self.assertEqual(qs['selected__sum'], Book.objects.count()) + def test_empty_queryset_annotation(self): qs = Author.objects.annotate( empty=Subquery(Author.objects.values('id').none()) |
