Do not return None when evaluating domain with in operator

When the operator is 'in' and the value contains None, Field._domain_add_null
adds an equal operator against NULL. So this must be managed like the '='
operator.

issue9906
review332201005
This commit is contained in:
Cédric Krier
2021-03-20 12:33:09 +01:00
parent 4f3c27015e
commit d4e228a29f
2 changed files with 14 additions and 1 deletions
+10
View File
@@ -540,6 +540,11 @@ class DomainInversionTestCase(unittest.TestCase):
self.assertTrue(eval_domain(domain, {'x': [3]}))
self.assertTrue(eval_domain(domain, {'x': [3, 4]}))
self.assertFalse(eval_domain(domain, {'x': [1, 2]}))
self.assertFalse(eval_domain(domain, {'x': None}))
domain = [['x', 'in', [1, None]]]
self.assertTrue(eval_domain(domain, {'x': None}))
self.assertFalse(eval_domain(domain, {'x': 2}))
domain = [['x', 'not in', [3, 5]]]
self.assertFalse(eval_domain(domain, {'x': 3}))
@@ -547,6 +552,11 @@ class DomainInversionTestCase(unittest.TestCase):
self.assertFalse(eval_domain(domain, {'x': [3]}))
self.assertFalse(eval_domain(domain, {'x': [3, 4]}))
self.assertTrue(eval_domain(domain, {'x': [1, 2]}))
self.assertFalse(eval_domain(domain, {'x': None}))
domain = [['x', 'not in', [1, None]]]
self.assertFalse(eval_domain(domain, {'x': None}))
self.assertTrue(eval_domain(domain, {'x': 2}))
domain = [['x', 'like', 'abc']]
self.assertTrue(eval_domain(domain, {'x': 'abc'}))
+4 -1
View File
@@ -96,7 +96,10 @@ def eval_leaf(part, context, boolop=operator.and_):
return bool(context.get(field.split('.')[0]))
context_field = context.get(field)
if (operand not in {'=', '!='}
and (context_field is None or value is None)):
and (context_field is None or value is None)
and not (operand in {'in', 'not in'}
and context_field is None
and (isinstance(value, (list, tuple)) and None in value))):
return
if isinstance(context_field, datetime.date) and not value:
if isinstance(context_field, datetime.datetime):