summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-07-24 17:38:28 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-25 12:39:55 +0200
commit1853383969a4c53bbeba998757c30410bd3df4bb (patch)
treea36769cd0b3d64815f2af1feb4f4e8e96c7ed390 /tests
parentf13147c8de725eed7038941758469aeb9bd66503 (diff)
Fixed #27995 -- Added error messages on unsupported operations following union(), intersection(), and difference().
Diffstat (limited to 'tests')
-rw-r--r--tests/queries/test_qs_combinators.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index e7cfbfb0d1..668d5e6ad6 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -1,3 +1,4 @@
+from django.db import connection
from django.db.models import Exists, F, IntegerField, OuterRef, Value
from django.db.utils import DatabaseError, NotSupportedError
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
@@ -258,3 +259,29 @@ class QuerySetSetOperationTests(TestCase):
numbers = list(range(10))
self.assertNumbersEqual(union.order_by('num'), numbers)
self.assertNumbersEqual(union.order_by('other_num'), reversed(numbers))
+
+ def test_unsupported_operations_on_combined_qs(self):
+ qs = Number.objects.all()
+ msg = 'Calling QuerySet.%s() after %s() is not supported.'
+ combinators = ['union']
+ if connection.features.supports_select_difference:
+ combinators.append('difference')
+ if connection.features.supports_select_intersection:
+ combinators.append('intersection')
+ for combinator in combinators:
+ for operation in (
+ 'annotate',
+ 'defer',
+ 'exclude',
+ 'extra',
+ 'filter',
+ 'only',
+ 'prefetch_related',
+ 'select_related',
+ ):
+ with self.subTest(combinator=combinator, operation=operation):
+ with self.assertRaisesMessage(
+ NotSupportedError,
+ msg % (operation, combinator),
+ ):
+ getattr(getattr(qs, combinator)(qs), operation)()