From 22480561670857e74a980b7a4b13d64eff9a8781 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 29 Apr 2014 15:09:16 +0200 Subject: [PATCH] [FIX] routing_type meta info was populated too late in routing_map() Could not call methods outside of an http request context bzr revid: fme@openerp.com-20140429130916-7zuyzhf2ebcrlbhn --- openerp/http.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/openerp/http.py b/openerp/http.py index c9181d2c211..83bcf81575f 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -601,6 +601,16 @@ class ControllerType(type): # flag old-style methods with req as first argument for k, v in attrs.items(): if inspect.isfunction(v) and hasattr(v, 'original_func'): + # Set routing type on original functions + routing_type = v.routing.get('type') + parent = [claz for claz in bases if isinstance(claz, ControllerType) and hasattr(claz, k)] + parent_routing_type = getattr(parent[0], k).original_func.routing_type if parent else routing_type or 'http' + if routing_type is not None and routing_type is not parent_routing_type: + routing_type = parent_routing_type + _logger.warn("Subclass re-defines with different type than original." + " Will use original type: %r" % (cls.__module__, cls.__name__, k, parent_routing_type)) + v.original_func.routing_type = routing_type or parent_routing_type + spec = inspect.getargspec(v.original_func) first_arg = spec.args[1] if len(spec.args) >= 2 else None if first_arg in ["req", "request"]: @@ -660,15 +670,6 @@ def routing_map(modules, nodb_only, converters=None): for claz in reversed(mv.im_class.mro()): fn = getattr(claz, mv.func_name, None) if fn and hasattr(fn, 'routing') and fn not in methods_done: - fn_type = fn.routing.get('type') - if not routing_type: - routing_type = fn_type - else: - if fn_type and routing_type != fn_type: - _logger.warn("Subclass re-defines with different type than original." - " Will use original type: %r", fn.__module__, fn.__name__, routing_type) - fn.routing['type'] = routing_type - fn.original_func.routing_type = routing_type methods_done.append(fn) routing.update(fn.routing) if not nodb_only or nodb_only == (routing['auth'] == "none"):