[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>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user