Fixed #25718 -- Made a JSONField lookup value of None match keys that have a null value.

This commit is contained in:
Dmitry Dygalo 2018-02-20 16:47:12 +01:00 committed by Tim Graham
parent 4fe5d84666
commit c979c0a2b8
9 changed files with 70 additions and 5 deletions

View file

@ -1083,8 +1083,8 @@ class Query:
lookup = lookup_class(lhs, rhs)
# Interpret '__exact=None' as the sql 'is NULL'; otherwise, reject all
# uses of None as a query value.
if lookup.rhs is None:
# uses of None as a query value unless the lookup supports it.
if lookup.rhs is None and not lookup.can_use_none_as_rhs:
if lookup_name not in ('exact', 'iexact'):
raise ValueError("Cannot use None as a query value")
return lhs.get_lookup('isnull')(lhs, True)
@ -1215,7 +1215,7 @@ class Query:
clause.add(condition, AND)
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):
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