summaryrefslogtreecommitdiff
path: root/tests/queries
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2021-09-23 18:40:54 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-24 06:59:22 +0200
commitf997c81472b96a1cf48a1a19a4fe974683455a50 (patch)
tree852242b75f8c3a69fbaa0cdb2c169c09c94e63c9 /tests/queries
parent25cbd1e6aa4178c31d60e3900a5bd4aa177c01c9 (diff)
downloaddjango-f997c81472b96a1cf48a1a19a4fe974683455a50.tar.gz
Fixed #33127 -- Added error messages on | and & operators with combined querysets.
Diffstat (limited to 'tests/queries')
-rw-r--r--tests/queries/test_qs_combinators.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index 351a401902..89d08ef6db 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -441,3 +441,24 @@ class QuerySetSetOperationTests(TestCase):
with self.subTest(combinator=combinator):
with self.assertRaisesMessage(NotSupportedError, msg % combinator):
getattr(qs, combinator)(qs).get(num=2)
+
+ def test_operator_on_combined_qs_error(self):
+ qs = Number.objects.all()
+ msg = 'Cannot use %s operator with combined queryset.'
+ combinators = ['union']
+ if connection.features.supports_select_difference:
+ combinators.append('difference')
+ if connection.features.supports_select_intersection:
+ combinators.append('intersection')
+ operators = [
+ ('|', operator.or_),
+ ('&', operator.and_),
+ ]
+ for combinator in combinators:
+ combined_qs = getattr(qs, combinator)(qs)
+ for operator_, operator_func in operators:
+ with self.subTest(combinator=combinator):
+ with self.assertRaisesMessage(TypeError, msg % operator_):
+ operator_func(qs, combined_qs)
+ with self.assertRaisesMessage(TypeError, msg % operator_):
+ operator_func(combined_qs, qs)