diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index c94075e946b..374438b32c0 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -523,22 +523,22 @@ class Website(Home): # find the action_id: either an xml_id, the path, or an ID if isinstance(path_or_xml_id_or_id, str) and '.' in path_or_xml_id_or_id: - action = request.env.ref(path_or_xml_id_or_id, raise_if_not_found=False) + action = request.env.ref(path_or_xml_id_or_id, raise_if_not_found=False).sudo() if not action: - action = ServerActions.search([('website_path', '=', path_or_xml_id_or_id), ('website_published', '=', True)], limit=1) + action = ServerActions.sudo().search( + [('website_path', '=', path_or_xml_id_or_id), ('website_published', '=', True)], limit=1) if not action: try: action_id = int(path_or_xml_id_or_id) + action = ServerActions.sudo().browse(action_id).exists() except ValueError: pass - # check it effectively exists - if action_id: - action = ServerActions.browse(action_id).exists() # run it, return only if we got a Response object if action: if action.state == 'code' and action.website_published: - action_res = action.run() + # use main session env for execution + action_res = ServerActions.browse(action.id).run() if isinstance(action_res, werkzeug.wrappers.Response): return action_res