1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

Fixed #33127 -- Added error messages on | and & operators with combined querysets.

This commit is contained in:
Hasan Ramezani
2021-09-23 18:40:54 +02:00
committed by Mariusz Felisiak
parent 25cbd1e6aa
commit f997c81472
2 changed files with 27 additions and 0 deletions

View File

@@ -325,6 +325,7 @@ class QuerySet:
return cls
def __and__(self, other):
self._check_operator_queryset(other, '&')
self._merge_sanity_check(other)
if isinstance(other, EmptyQuerySet):
return other
@@ -336,6 +337,7 @@ class QuerySet:
return combined
def __or__(self, other):
self._check_operator_queryset(other, '|')
self._merge_sanity_check(other)
if isinstance(self, EmptyQuerySet):
return other
@@ -1430,6 +1432,10 @@ class QuerySet:
% (operation_name, self.query.combinator)
)
def _check_operator_queryset(self, other, operator_):
if self.query.combinator or other.query.combinator:
raise TypeError(f'Cannot use {operator_} operator with combined queryset.')
class InstanceCheckMeta(type):
def __instancecheck__(self, instance):