From fb4cf35368eb5defede887d1ecd481c4f787161f Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Fri, 19 Mar 2021 16:07:19 +0000 Subject: [PATCH] [FIX] base: View error reporting can lack a context A context is attached to the ValidationError object when elements in the view arch are broken. This context helps to locate the error in the source file. When the view processing fails outside of the arch evaluation, such context is missing. closes odoo/odoo#68157 Signed-off-by: Julien Castiaux --- odoo/addons/base/models/ir_ui_view.py | 6 ++++-- odoo/tools/convert.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 52a4dd0a136..675000fd7c6 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -390,10 +390,12 @@ actual arch. continue view_doc = etree.fromstring(view_arch_utf8) except ValueError as e: - raise ValidationError(_( + err = ValidationError(_( "Error while validating view:\n\n%(error)s", error=tools.ustr(e), - )).with_traceback(e.__traceback__) from None + )).with_traceback(e.__traceback__) + err.context = None + raise err from None try: # verify that all fields used are valid, etc. diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py index eac9734ac55..34651e97b52 100644 --- a/odoo/tools/convert.py +++ b/odoo/tools/convert.py @@ -684,7 +684,7 @@ form: module.record_id""" % (xml_id,) msg = "while parsing {file}:{viewline}\n{err}\n\nView error context:\n{context}\n".format( file=rec.getroottree().docinfo.URL, viewline=rec.sourceline, - context=pprint.pformat(err.context), + context=pprint.pformat(getattr(err, 'context', None) or '-no context-'), err=err.args[0], ) _logger.debug(msg, exc_info=True)