From f347865161a6de20e5c42d0dca97e8571822f17f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 23 Nov 2017 08:38:19 +0100 Subject: [PATCH] [FIX] base_import_module: decoding error In P3, `url_path` is already decoded in UTF-8, and therefore cannot be decoded. opw-783978 Closes #20912 --- addons/base_import_module/models/ir_module.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index 33cd83cf1c6..aaa1e69946a 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -11,7 +11,7 @@ from os.path import join as opj from odoo import api, fields, models, _ from odoo.exceptions import UserError from odoo.modules import load_information_from_description_file -from odoo.tools import convert_file, exception_to_unicode +from odoo.tools import convert_file, exception_to_unicode, pycompat from odoo.tools.osutil import tempdir _logger = logging.getLogger(__name__) @@ -78,8 +78,9 @@ class IrModule(models.Model): full_path = opj(root, static_file) with open(full_path, 'rb') as fp: data = base64.b64encode(fp.read()) - url_path = '/%s%s' % (module, full_path.split(path)[1].replace(os.path.sep, '/')) - url_path = url_path.decode(sys.getfilesystemencoding()) + url_path = '/{}{}'.format(module, full_path.split(path)[1].replace(os.path.sep, '/')) + if not isinstance(url_path, pycompat.text_type): + url_path = url_path.decode(sys.getfilesystemencoding()) filename = os.path.split(url_path)[1] values = dict( name=filename,