1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[3.2.x] Fixed #32455 -- Allowed right combining Q() with boolean expressions.

Backport of f2bef2b7bc from master
This commit is contained in:
Hasan Ramezani
2021-02-18 14:01:48 +01:00
committed by Mariusz Felisiak
parent 732cf4c5b4
commit 0debc6ba5b
2 changed files with 11 additions and 1 deletions

View File

@@ -803,6 +803,14 @@ class BasicExpressionsTests(TestCase):
Employee.objects.filter(Exists(is_poc) | Q(salary__lt=15)),
[self.example_inc.ceo, self.max],
)
self.assertCountEqual(
Employee.objects.filter(Q(salary__gte=30) & Exists(is_ceo)),
[self.max],
)
self.assertCountEqual(
Employee.objects.filter(Q(salary__lt=15) | Exists(is_poc)),
[self.example_inc.ceo, self.max],
)
def test_boolean_expression_combined_with_empty_Q(self):
is_poc = Company.objects.filter(point_of_contact=OuterRef('pk'))
@@ -810,7 +818,9 @@ class BasicExpressionsTests(TestCase):
self.gmbh.save()
tests = [
Exists(is_poc) & Q(),
Q() & Exists(is_poc),
Exists(is_poc) | Q(),
Q() | Exists(is_poc),
]
for conditions in tests:
with self.subTest(conditions):