summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2019-11-18 15:17:02 +0000
committerRaphael Collet <rco@odoo.com>2019-11-18 15:17:02 +0000
commitd2ff759ec08bf50134bf6569983a8523556e8cd6 (patch)
tree40a177603488b5f893b1b8ce387bb0978647e3e3
parent69cbab713a18f7f52e5a11526af185d6378265db (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>
-rw-r--r--odoo/tools/view_validation.py40
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)