diff options
| author | Raphael Collet <rco@odoo.com> | 2019-11-18 15:17:02 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-11-18 15:17:02 +0000 |
| commit | d2ff759ec08bf50134bf6569983a8523556e8cd6 (patch) | |
| tree | 40a177603488b5f893b1b8ce387bb0978647e3e3 /odoo | |
| parent | 69cbab713a18f7f52e5a11526af185d6378265db (diff) | |
[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) <rco@openerp.com>
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/tools/view_validation.py | 40 |
1 files 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) |
