From 0ec0a4a32e98f2288e419dcb0627cfd972f32034 Mon Sep 17 00:00:00 2001 From: Richard Mathot Date: Tue, 9 Jul 2019 12:26:46 +0000 Subject: [PATCH] [FIX] models: avoid Unicode error when translating that error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch fa492d87f42f97d05ba93255a77e24c35158fe62 has been backported from Odoo 12.0, that runs on Python 3. The string '\n\n({} {}, {} {})' to be formatted is a byte-string in Python 2, while the return value of _() is always a unicode-string. As format() is (too?) nice, it attempts to convert the unicode-strings into ascii in order to inject them in the format pattern. With some languages that are written in ascii, this works -- by chance. When you use non-ascii languages like Japanese, it fails. We then fix that issue by using unicode-strings in the formatting pattern. #OneCharacterPatch B-) opw-2032016 ----------------------------- For full technical understanding: Python 2.7.16 (default, Mar 11 2019, 18:59:25) [GCC 8.2.1 20181127] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> '{}'.format('test') 'test' >>> '{}'.format(u'test') 'test' >>> '{}'.format(u'エ') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u30a8' in position 0: ordinal not in range(128) >>> u'{}'.format(u'エ') u'\u30a8' closes odoo/odoo#34698 Signed-off-by: Richard Mathot (rim) --- odoo/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odoo/models.py b/odoo/models.py index 577ef080197..3c9daa02ce9 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4474,7 +4474,7 @@ class BaseModel(object): # mark missing records in cache with a failed value exc = MissingError( _("Record does not exist or has been deleted.") - + '\n\n({} {}, {} {})'.format(_('Records:'), (self - existing).ids[:6], _('User:'), self._uid) + + u'\n\n({} {}, {} {})'.format(_('Records:'), (self - existing).ids[:6], _('User:'), self._uid) ) (self - existing)._cache.update(FailedValue(exc)) return existing