[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...)
This commit is contained in:
Xavier Morel 2015-01-29 16:11:16 +01:00
parent 54e75b0286
commit 3d85eaa591
1 changed files with 2 additions and 2 deletions

View File

@ -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))