diff --git a/addons/web/http.py b/addons/web/http.py index 22b5522fa22..96b7275343d 100644 --- a/addons/web/http.py +++ b/addons/web/http.py @@ -471,18 +471,20 @@ from werkzeug.local import LocalStack _request_stack = LocalStack() -def set_request(request): - class with_obj(object): - def __enter__(self): - _request_stack.push(request) - def __exit__(self, *args): - _request_stack.pop() - return with_obj() +@contextlib.contextmanager +def set_request(req): + _request_stack.push(req) + try: + yield + finally: + _request_stack.pop() + + +request = _request_stack() """ A global proxy that always redirect to the current request object. """ -request = _request_stack() #---------------------------------------------------------- # Controller registration with a metaclass