mirror of https://github.com/django/django.git
[4.2.x] Fixed #34254 -- Fixed return value of Exists() with empty queryset.
Thanks Simon Charette for reviews.
Backport of 246eb4836a
from main
This commit is contained in:
parent
9eae81724d
commit
f210ad1b98
|
@ -1548,6 +1548,7 @@ class Subquery(BaseExpression, Combinable):
|
||||||
class Exists(Subquery):
|
class Exists(Subquery):
|
||||||
template = "EXISTS(%(subquery)s)"
|
template = "EXISTS(%(subquery)s)"
|
||||||
output_field = fields.BooleanField()
|
output_field = fields.BooleanField()
|
||||||
|
empty_result_set_value = False
|
||||||
|
|
||||||
def __init__(self, queryset, **kwargs):
|
def __init__(self, queryset, **kwargs):
|
||||||
super().__init__(queryset, **kwargs)
|
super().__init__(queryset, **kwargs)
|
||||||
|
|
|
@ -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):
|
def test_annotation_exists_aggregate_values_chaining(self):
|
||||||
qs = (
|
qs = (
|
||||||
Book.objects.values("publisher")
|
Book.objects.values("publisher")
|
||||||
|
|
Loading…
Reference in New Issue