From d2ff759ec08bf50134bf6569983a8523556e8cd6 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 18 Nov 2019 15:17:02 +0000 Subject: [PATCH] [IMP] tools: make domain validation less strict We do not want to block developers from using dynamic domains like: domain="country_id and [('country_id', 'in', [False, country_id])] or []" closes odoo/odoo#40445 Signed-off-by: Raphael Collet (rco) --- odoo/tools/view_validation.py | 40 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/odoo/tools/view_validation.py b/odoo/tools/view_validation.py index 89bd11145e8..8ea0ccfc1e0 100644 --- a/odoo/tools/view_validation.py +++ b/odoo/tools/view_validation.py @@ -104,27 +104,31 @@ def get_domain_identifiers(expr): if not condition: raise ValueError("Expression is not a valid domain") - check(isinstance(expr, ast.List)) fnames = set() vnames = set() - leaves = list(ast.iter_child_nodes(expr)) - check(isinstance(leaves.pop(), ast.Load)) - for leaf in leaves: - if isinstance(leaf, ast.Str): - # note: this doesn't check the and/or structure - check(leaf.s in ('&', '|', '!')) - else: - check(isinstance(leaf, (ast.List, ast.Tuple))) - tuple_ = list(ast.iter_child_nodes(leaf)) - check(isinstance(tuple_.pop(), ast.Load) and len(tuple_) == 3) - lhs, operator, rhs = tuple_ - if isinstance(lhs, ast.Str): - fnames.add(lhs.s) + + if isinstance(expr, ast.List): + leaves = list(ast.iter_child_nodes(expr)) + check(isinstance(leaves.pop(), ast.Load)) + for leaf in leaves: + if isinstance(leaf, ast.Str): + # note: this doesn't check the and/or structure + check(leaf.s in ('&', '|', '!')) else: - # limitation: we do not list fnames in this case - vnames.update(get_variable_names(lhs)) - check(isinstance(operator, ast.Str)) - vnames.update(get_variable_names(rhs)) + check(isinstance(leaf, (ast.List, ast.Tuple))) + tuple_ = list(ast.iter_child_nodes(leaf)) + check(isinstance(tuple_.pop(), ast.Load) and len(tuple_) == 3) + lhs, operator, rhs = tuple_ + if isinstance(lhs, ast.Str): + fnames.add(lhs.s) + else: + # limitation: we do not list fnames in this case + vnames.update(get_variable_names(lhs)) + check(isinstance(operator, ast.Str)) + vnames.update(get_variable_names(rhs)) + else: + # limitation: we do not list fnames in this case + vnames.update(get_variable_names(expr)) return (fnames, vnames)