From 5ea09c2ed8aed3e0d8421db18b718c44ea418c8b Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Thu, 21 Nov 2019 15:14:18 +0000 Subject: [PATCH] [FIX] base: translate error messages at failed import Forward-port of ffee5bdbd12b0080349da515d01981943355d0cd; because of 1a315e87b05fcbdefcb3db6d8d4837f6cc3e835c by the same author, only the following are left: - we need to translate the untranslated message - give the temporary cursor a name different from cursor or cr so that _'s _get_cr method does not get the closed cursor closes odoo/odoo#41140 X-original-commit: 926873031d479ec96ca122fe8c3a481b31f2a32b Signed-off-by: Nans Lefebvre (len) --- odoo/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index bb1c305daa2..ddc6a518acc 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -940,6 +940,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): batch.clear() batch_xml_ids.clear() + unknown_msg = _(u"Unknown database error: '%s'") try: cr.execute('SAVEPOINT model_load_save') except psycopg2.InternalError as e: @@ -947,7 +948,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): # already logged if not any(message['type'] == 'error' for message in messages): info = data_list[0]['info'] - messages.append(dict(info, type='error', message=u"Unknown database error: '%s'" % e)) + messages.append(dict(info, type='error', message=unknown_msg % e)) return # try to create in batch @@ -6212,8 +6213,8 @@ def convert_pgerror_not_null(model, fields, info, e): def convert_pgerror_unique(model, fields, info, e): # new cursor since we're probably in an error handler in a blown # transaction which may not have been rollbacked/cleaned yet - with closing(model.env.registry.cursor()) as cr: - cr.execute(""" + with closing(model.env.registry.cursor()) as cr_tmp: + cr_tmp.execute(""" SELECT conname AS "constraint name", t.relname AS "table name", @@ -6226,7 +6227,7 @@ def convert_pgerror_unique(model, fields, info, e): JOIN pg_class t ON t.oid = conrelid WHERE conname = %s """, [e.diag.constraint_name]) - constraint, table, ufields = cr.fetchone() or (None, None, None) + constraint, table, ufields = cr_tmp.fetchone() or (None, None, None) # if the unique constraint is on an expression or on an other table if not ufields or model._table != table: return {'message': tools.ustr(e)}