mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #23797 -- Fixed QuerySet.exclude() when rhs is a nullable column.
This commit is contained in:
committed by
Mariusz Felisiak
parent
b7b7df5fbc
commit
512da9d585
@@ -1324,9 +1324,7 @@ class Query(BaseExpression):
|
||||
require_outer = lookup_type == 'isnull' and condition.rhs is True and not current_negated
|
||||
if current_negated and (lookup_type != 'isnull' or condition.rhs is False) and condition.rhs is not None:
|
||||
require_outer = True
|
||||
if (lookup_type != 'isnull' and (
|
||||
self.is_nullable(targets[0]) or
|
||||
self.alias_map[join_list[-1]].join_type == LOUTER)):
|
||||
if lookup_type != 'isnull':
|
||||
# The condition added here will be SQL like this:
|
||||
# NOT (col IS NOT NULL), where the first NOT is added in
|
||||
# upper layers of code. The reason for addition is that if col
|
||||
@@ -1336,9 +1334,18 @@ class Query(BaseExpression):
|
||||
# (col IS NULL OR col != someval)
|
||||
# <=>
|
||||
# NOT (col IS NOT NULL AND col = someval).
|
||||
lookup_class = targets[0].get_lookup('isnull')
|
||||
col = self._get_col(targets[0], join_info.targets[0], alias)
|
||||
clause.add(lookup_class(col, False), AND)
|
||||
if (
|
||||
self.is_nullable(targets[0]) or
|
||||
self.alias_map[join_list[-1]].join_type == LOUTER
|
||||
):
|
||||
lookup_class = targets[0].get_lookup('isnull')
|
||||
col = self._get_col(targets[0], join_info.targets[0], alias)
|
||||
clause.add(lookup_class(col, False), AND)
|
||||
# If someval is a nullable column, someval IS NOT NULL is
|
||||
# added.
|
||||
if isinstance(value, Col) and self.is_nullable(value.target):
|
||||
lookup_class = value.target.get_lookup('isnull')
|
||||
clause.add(lookup_class(value, False), AND)
|
||||
return clause, used_joins if not require_outer else ()
|
||||
|
||||
def add_filter(self, filter_clause):
|
||||
|
||||
Reference in New Issue
Block a user