From 82e4bb826a6bbdad040a5415f0f7b85c5cb0fba5 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 7 May 2013 12:40:25 +0200 Subject: [PATCH] [FIX] ir.ui.menu: safer eval of action contexts when computing needaction Unchecked eval of a context may fail for various reasons, such as the use of client-side variables like `active_id` bzr revid: odo@openerp.com-20130507104025-em6w03pcxeq92az9 --- openerp/addons/base/ir/ir_ui_menu.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_ui_menu.py b/openerp/addons/base/ir/ir_ui_menu.py index 647f714fd81..529878b8750 100644 --- a/openerp/addons/base/ir/ir_ui_menu.py +++ b/openerp/addons/base/ir/ir_ui_menu.py @@ -298,13 +298,21 @@ class ir_ui_menu(osv.osv): - the needaction counter of the related action, taking into account the action domain """ + if context is None: + context = {} res = {} menu_ids = set() for menu in self.browse(cr, uid, ids, context=context): menu_ids.add(menu.id) ctx = None if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.context: - ctx = eval(menu.action.context, context) or None + try: + # use magical UnquoteEvalContext to ignore undefined client-side variables such as `active_id` + eval_ctx = tools.UnquoteEvalContext(**context) + ctx = eval(menu.action.context, locals_dict=eval_ctx, nocopy=True) or None + except Exception: + # if the eval still fails for some reason, we'll simply skip this menu + pass menu_ref = ctx and ctx.get('needaction_menu_ref') if menu_ref: if not isinstance(menu_ref, list):