[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 <Julien00859@users.noreply.github.com>
This commit is contained in:
Julien Castiaux
2021-03-19 16:13:17 +00:00
parent 09ce16861b
commit fb4cf35368
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -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.
+1 -1
View File
@@ -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)