From 4d6d5c8290ec9640ad91e70b3b6836f7232fbb4d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 17 May 2017 13:56:46 +0200 Subject: [PATCH] [FIX] P3: stupid use of hasattr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Python 2, hasattr swallows *any* exception raised during the access. In Python 3, it only swallows AttributeError. Accessing an attribute on an unbound threadlocal proxy raises RuntimeError, while running test_ir_http_mimetype ``request`` is unbound, in Python 2 ``hasattr`` would return ``False`` on an unbound threadlocal, in Python 3 it lets ``RuntimeError`` pass through blowing up the test. Fix this by just checking if the threadlocal is bound by using it as a boolean… --- odoo/addons/base/ir/ir_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odoo/addons/base/ir/ir_http.py b/odoo/addons/base/ir/ir_http.py index ff4654cf6c9..0aa1abc52ca 100644 --- a/odoo/addons/base/ir/ir_http.py +++ b/odoo/addons/base/ir/ir_http.py @@ -323,7 +323,7 @@ class IrHttp(models.AbstractModel): headers += [('Content-Type', mimetype), ('X-Content-Type-Options', 'nosniff')] # cache - etag = hasattr(request, 'httprequest') and request.httprequest.headers.get('If-None-Match') + etag = bool(request) and request.httprequest.headers.get('If-None-Match') retag = '"%s"' % hashlib.md5(last_update).hexdigest() status = status or (304 if etag == retag else 200) headers.append(('ETag', retag))