diff options
| author | Raj Desai <rajdesai024@gmail.com> | 2023-01-20 03:15:05 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-26 20:25:18 +0100 |
| commit | f210ad1b980a40345ab66b2f0c4f5b9610eb07ac (patch) | |
| tree | 218edf9cc3cb19f52815b26906f3a98f8f54380c | |
| parent | 9eae81724d80b3b2901377f63ee560f9c56ffd63 (diff) | |
[4.2.x] Fixed #34254 -- Fixed return value of Exists() with empty queryset.
Thanks Simon Charette for reviews.
Backport of 246eb4836a6fb967880f838aa0d22ecfdca8b6f1 from main
| -rw-r--r-- | django/db/models/expressions.py | 1 | ||||
| -rw-r--r-- | tests/annotations/tests.py | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index c270ef16c7..fc1d94fefb 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1548,6 +1548,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) diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index d05af552b4..e0cdbf1e0b 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -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") |
