From 60de7719798429fd5ecf90443333bb2936052a03 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 25 Aug 2015 18:10:10 +0200 Subject: [PATCH] [FIX] base: adapt _serve_attachment for saas-6 Commit c2cbb75319dfde57420bf38f8f057ad2f55cfcec modified the logic of _serve_attachment for empty files. After this patch, empty files are returned with status 200 and a valid ETag, for proper browser caching. However the new stored `checksum` field in saas-6 was not being computed for empty files, resulting in errors when those files were being served. This commit updates the logic to restore the caching behavior for empty files after the forward-port to saas-6. --- openerp/addons/base/ir/ir_attachment.py | 5 ++--- openerp/addons/base/ir/ir_http.py | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/ir/ir_attachment.py b/openerp/addons/base/ir/ir_attachment.py index 2dffe9d0b86..73a8867a98d 100644 --- a/openerp/addons/base/ir/ir_attachment.py +++ b/openerp/addons/base/ir/ir_attachment.py @@ -255,9 +255,8 @@ class ir_attachment(osv.osv): """ compute the checksum for the given datas :param bin_data : datas in its binary form """ - if bin_data: - return hashlib.sha1(bin_data).hexdigest() - return False + # an empty file has a checksum too (for caching) + return hashlib.sha1(bin_data or '').hexdigest() def _compute_mimetype(self, values): """ compute the mimetype of the given values diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index cc2e01890b2..48479528bd0 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -107,6 +107,7 @@ class ir_http(osv.AbstractModel): wdate = attach[0]['__last_update'] datas = attach[0]['datas'] or '' name = attach[0]['name'] + checksum = attach[0]['checksum'] or hashlib.sha1(datas).hexdigest() if (not datas and name != request.httprequest.path and name.startswith(('http://', 'https://', '/'))): @@ -120,7 +121,7 @@ class ir_http(osv.AbstractModel): # just in case we have a timestamp without microseconds response.last_modified = datetime.datetime.strptime(wdate, server_format) - response.set_etag(attach[0]['checksum']) + response.set_etag(checksum) response.make_conditional(request.httprequest) if response.status_code == 304: