From a096ae0080bc6555a8b832e87d4de6b827257304 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 21 May 2014 19:12:37 +0200 Subject: [PATCH] [FIX] http: force rolleback for failed http request 1st issue: When an exception was raised, it was badly handled by the website in case of website_enabled key. The response page was generated without calling super. The WebRequest object being responsible to rollback the transaction in case of errors. 2sd issue: The _failed attribute is required to rollback the transaction in an WebRequest object. Previously it was only set in the JsonRequest object (which inherit from WebRequest), replace by call to super. The attribute _failed is now set in the WebRequest object. --- addons/website/models/ir_http.py | 3 ++- openerp/http.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 696734b5f05..f724eb2fa5a 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -99,6 +99,7 @@ class ir_http(orm.AbstractModel): werkzeug.exceptions.abort(werkzeug.utils.redirect(url)) def _handle_exception(self, exception=None, code=500): + res = super(ir_http, self)._handle_exception(exception) if isinstance(exception, werkzeug.exceptions.HTTPException) and hasattr(exception, 'response') and exception.response: return exception.response if getattr(request, 'website_enabled', False) and request.website: @@ -136,7 +137,7 @@ class ir_http(orm.AbstractModel): html = request.website._render('website.http_error', values) return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8') - return super(ir_http, self)._handle_exception(exception) + return res class ModelConverter(ir.ir_http.ModelConverter): def __init__(self, url_map, model=False): diff --git a/openerp/http.py b/openerp/http.py index 24f538f3828..68c206793bc 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -207,7 +207,7 @@ class WebRequest(object): """Called within an except block to allow converting exceptions to abitrary responses. Anything returned (except None) will be used as response.""" - raise + self._failed = exception # prevent tx commit def _call_function(self, *args, **kwargs): request = self @@ -374,8 +374,8 @@ class JsonRequest(WebRequest): """Called within an except block to allow converting exceptions to abitrary responses. Anything returned (except None) will be used as response.""" + super(JsonRequest, self)._handle_exception(exception) _logger.exception("Exception during JSON request handling.") - self._failed = exception # prevent tx commit error = { 'code': 200, 'message': "OpenERP Server Error",