diff options
| author | Jonathan Richards <jonathan@golorry.com> | 2021-03-14 14:00:40 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-17 21:53:39 +0100 |
| commit | 00b0786de533dbb3f6208d8d5eaddbf765b4e5b8 (patch) | |
| tree | 10ad86b76142e46e3a82460b4c31aacefb9af383 /tests | |
| parent | 54f60bc85df7fe38ba6ef6779996d8544d340d3e (diff) | |
Fixed #32548 -- Fixed crash when combining Q() objects with boolean expressions.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/expressions/tests.py | 4 | ||||
| -rw-r--r-- | tests/queries/test_q.py | 22 |
2 files changed, 18 insertions, 8 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 82d8a9f351..eb1bfdc2be 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -833,6 +833,10 @@ class BasicExpressionsTests(TestCase): Q() & Exists(is_poc), Exists(is_poc) | Q(), Q() | Exists(is_poc), + Q(Exists(is_poc)) & Q(), + Q() & Q(Exists(is_poc)), + Q(Exists(is_poc)) | Q(), + Q() | Q(Exists(is_poc)), ] for conditions in tests: with self.subTest(conditions): diff --git a/tests/queries/test_q.py b/tests/queries/test_q.py index 6dcf36ce02..24a705f07f 100644 --- a/tests/queries/test_q.py +++ b/tests/queries/test_q.py @@ -1,6 +1,8 @@ -from django.db.models import F, Q +from django.db.models import Exists, F, OuterRef, Q from django.test import SimpleTestCase +from .models import Tag + class QTests(SimpleTestCase): def test_combine_and_empty(self): @@ -39,17 +41,14 @@ class QTests(SimpleTestCase): q = Q(price__gt=F('discounted_price')) path, args, kwargs = q.deconstruct() self.assertEqual(path, 'django.db.models.Q') - self.assertEqual(args, ()) - self.assertEqual(kwargs, {'price__gt': F('discounted_price')}) + self.assertEqual(args, (('price__gt', F('discounted_price')),)) + self.assertEqual(kwargs, {}) def test_deconstruct_negated(self): q = ~Q(price__gt=F('discounted_price')) path, args, kwargs = q.deconstruct() - self.assertEqual(args, ()) - self.assertEqual(kwargs, { - 'price__gt': F('discounted_price'), - '_negated': True, - }) + self.assertEqual(args, (('price__gt', F('discounted_price')),)) + self.assertEqual(kwargs, {'_negated': True}) def test_deconstruct_or(self): q1 = Q(price__gt=F('discounted_price')) @@ -88,6 +87,13 @@ class QTests(SimpleTestCase): self.assertEqual(args, (Q(price__gt=F('discounted_price')),)) self.assertEqual(kwargs, {}) + def test_deconstruct_boolean_expression(self): + tagged = Tag.objects.filter(category=OuterRef('pk')) + q = Q(Exists(tagged)) + _, args, kwargs = q.deconstruct() + self.assertEqual(args, (Exists(tagged),)) + self.assertEqual(kwargs, {}) + def test_reconstruct(self): q = Q(price__gt=F('discounted_price')) path, args, kwargs = q.deconstruct() |
