Fixed #34254 -- Fixed return value of Exists() with empty queryset.

Thanks Simon Charette for reviews.
This commit is contained in:
Raj Desai 2023-01-20 03:15:05 +05:30 committed by Mariusz Felisiak
parent 7eb5391b71
commit 246eb4836a
2 changed files with 9 additions and 0 deletions

View File

@ -1546,6 +1546,7 @@ class Subquery(BaseExpression, Combinable):
class Exists(Subquery):
template = "EXISTS(%(subquery)s)"
output_field = fields.BooleanField()
empty_result_set_value = False
def __init__(self, queryset, **kwargs):
super().__init__(queryset, **kwargs)

View File

@ -1017,6 +1017,14 @@ class NonAggregateAnnotationTestCase(TestCase):
],
)
def test_annotation_exists_none_query(self):
self.assertIs(
Author.objects.annotate(exists=Exists(Company.objects.none()))
.get(pk=self.a1.pk)
.exists,
False,
)
def test_annotation_exists_aggregate_values_chaining(self):
qs = (
Book.objects.values("publisher")