summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohannes Dollinger <emulbreh@googlemail.com>2016-08-05 09:09:01 -0400
committerTim Graham <timograham@gmail.com>2016-08-08 10:43:33 -0400
commitc002a0d39f18694f5e8a07d86684fc793b063056 (patch)
tree8a6395bed9010d501783cdf1d65cf7b59f7079fc /tests
parent1410616e0e2637e4b0821620202bf62edc903b88 (diff)
Fixed #26517 -- Fixed ExpressionWrapper with empty queryset.
Diffstat (limited to 'tests')
-rw-r--r--tests/annotations/tests.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index d57f9ed0d7..28627e84ae 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -6,7 +6,7 @@ from decimal import Decimal
from django.core.exceptions import FieldDoesNotExist, FieldError
from django.db.models import (
BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
- IntegerField, Sum, Value,
+ IntegerField, Q, Sum, Value,
)
from django.db.models.functions import Lower
from django.test import TestCase, skipUnlessDBFeature
@@ -148,6 +148,19 @@ class NonAggregateAnnotationTestCase(TestCase):
combined = int(test.pages + test.rating)
self.assertEqual(b.combined, combined)
+ def test_empty_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(not book.selected for book in books))
+
+ books = Book.objects.annotate(
+ selected=ExpressionWrapper(Q(pk__in=Book.objects.none()), output_field=BooleanField())
+ )
+ self.assertEqual(len(books), Book.objects.count())
+ self.assertTrue(all(not book.selected for book in books))
+
def test_annotate_with_aggregation(self):
books = Book.objects.annotate(
is_book=Value(1, output_field=IntegerField()),