From d4e228a29fe717bf796b24526eddcc059aaae860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 20 Mar 2021 12:33:09 +0100 Subject: [PATCH] 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 --- trytond/tests/test_tools.py | 10 ++++++++++ trytond/tools/domain_inversion.py | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/trytond/tests/test_tools.py b/trytond/tests/test_tools.py index 58a32a89f7..8fd1433ad1 100644 --- a/trytond/tests/test_tools.py +++ b/trytond/tests/test_tools.py @@ -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'})) diff --git a/trytond/tools/domain_inversion.py b/trytond/tools/domain_inversion.py index 9c88530496..f68662eaee 100644 --- a/trytond/tools/domain_inversion.py +++ b/trytond/tools/domain_inversion.py @@ -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):