From 3d85eaa591f2935d4a7bef58286ba5cf7a4121ff Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 29 Jan 2015 16:11:16 +0100 Subject: [PATCH] [FIX] correctly handle empty binary fields in saveas Original code assumed the empty field would be missing or an empty string, b64decoding an empty string yields an other empty string which triggered a "not found" response. However Odoo returns ``False`` in case of an empty field, so that needs to be replaced by an empty string before decoding, as b64decode doesn't accept booleans as input (for some reason...) --- addons/web/controllers/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index da7c0b0e4f2..c652e678a34 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1097,7 +1097,7 @@ class Binary(http.Controller): res = Model.read(cr, uid, [int(id)], fields, context)[0] else: res = Model.default_get(cr, uid, fields, context) - filecontent = base64.b64decode(res.get(field, '')) + filecontent = base64.b64decode(res.get(field) or '') if not filecontent: return request.not_found() else: @@ -1129,7 +1129,7 @@ class Binary(http.Controller): res = Model.read([int(id)], fields, context)[0] else: res = Model.default_get(fields, context) - filecontent = base64.b64decode(res.get(field, '')) + filecontent = base64.b64decode(res.get(field) or '') if not filecontent: raise ValueError(_("No content found for field '%s' on '%s:%s'") % (field, model, id))