Skip to content
Snippets Groups Projects
Commit 8622469e authored by Jeremy Kersten's avatar Jeremy Kersten Committed by Martin Trigaux
Browse files

[IMP] base: improve log for wrong xpath


Before create_multi, in case of invalid syntax used in an XPath, only
the problematic record was displayed. It was not ideal for long
definition but still usable.
Since the views are created using create_multi, the whole file content
is displayed in the error traceback, making it almost impossible to
locate on files with multiple records.

closes odoo/odoo#43542

Signed-off-by: default avatarMartin Trigaux (mat) <mat@odoo.com>
parent 3f18db41
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,11 @@ from lxml import etree ...@@ -3,9 +3,11 @@ from lxml import etree
from lxml.builder import E from lxml.builder import E
import copy import copy
import itertools import itertools
import logging
from odoo.tools.translate import _ from odoo.tools.translate import _
from odoo.tools import SKIPPED_ELEMENT_TYPES from odoo.tools import SKIPPED_ELEMENT_TYPES
_logger = logging.getLogger(__name__)
def add_text_before(node, text): def add_text_before(node, text):
...@@ -51,7 +53,13 @@ def locate_node(arch, spec): ...@@ -51,7 +53,13 @@ def locate_node(arch, spec):
:return: a node in the source matching the spec :return: a node in the source matching the spec
""" """
if spec.tag == 'xpath': if spec.tag == 'xpath':
nodes = etree.ETXPath(spec.get('expr'))(arch) expr = spec.get('expr')
try:
xPath = etree.ETXPath(expr)
except etree.XPathSyntaxError:
_logger.error("XPathSyntaxError while parsing xpath %r", expr)
raise
nodes = xPath(arch)
return nodes[0] if nodes else None return nodes[0] if nodes else None
elif spec.tag == 'field': elif spec.tag == 'field':
# Only compare the field name: a field can be only once in a given view # Only compare the field name: a field can be only once in a given view
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment