From b0d1fc694633519c168ef0dff21d9a06529a9173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 7 Oct 2023 14:49:07 +0200 Subject: [PATCH] Do not get context for rule evaluation as root Since f2d4e71a704e the context must be computed for each rule so the loop must be outside of the root context used to browse the rules (to avoid infinite recursion) --- trytond/trytond/ir/rule.py | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/trytond/trytond/ir/rule.py b/trytond/trytond/ir/rule.py index 6e0f420c85..96723d4cc4 100644 --- a/trytond/trytond/ir/rule.py +++ b/trytond/trytond/ir/rule.py @@ -232,26 +232,27 @@ class Rule(ModelSQL, ModelView): clause_global = defaultdict(lambda: ['OR']) # Use root user without context to prevent recursion with transaction.set_user(0), transaction.set_context(user=0): - for rule in cls.browse(ids): - decoder = PYSONDecoder( - cls._get_context(rule.rule_group.model.model)) - assert rule.domain, ('Rule domain empty,' - 'check if migration was done') - dom = decoder.decode(rule.domain) - target_model = rule.rule_group.model.model - if target_model in model2field: - target_dom = ['OR'] - for field in model2field[target_model]: - target_dom.append((field, 'where', dom)) - dom = target_dom - if rule.rule_group.global_p: - clause_global[rule.rule_group].append(dom) - else: - clause[rule.rule_group].append(dom) + rules = cls.browse(ids) + for rule in rules: + decoder = PYSONDecoder( + cls._get_context(rule.rule_group.model.model)) + assert rule.domain, ('Rule domain empty,' + 'check if migration was done') + dom = decoder.decode(rule.domain) + target_model = rule.rule_group.model.model + if target_model in model2field: + target_dom = ['OR'] + for field in model2field[target_model]: + target_dom.append((field, 'where', dom)) + dom = target_dom + if rule.rule_group.global_p: + clause_global[rule.rule_group].append(dom) + else: + clause[rule.rule_group].append(dom) - if no_rules: - group_id = no_rules[0] - clause[RuleGroup(group_id)] = [] + if no_rules: + group_id = no_rules[0] + clause[RuleGroup(group_id)] = [] return clause, clause_global