[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#43590

X-original-commit: 8622469e1fdd4789cc45ed52093d0f329abca14e
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2020-01-20 16:31:09 +00:00
committed by Martin Trigaux
parent 54a95099bf
commit 5198b209f5
+9 -1
View File
@@ -3,9 +3,11 @@ from lxml import etree
from lxml.builder import E
import copy
import itertools
import logging
from odoo.tools.translate import _
from odoo.tools import SKIPPED_ELEMENT_TYPES
_logger = logging.getLogger(__name__)
def add_text_before(node, text):
@@ -51,7 +53,13 @@ def locate_node(arch, spec):
:return: a node in the source matching the spec
"""
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
elif spec.tag == 'field':
# Only compare the field name: a field can be only once in a given view