From 5198b209f5ebca543cb8c4b20b3a1ffe73dabc7c Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Sun, 19 Jan 2020 16:17:18 +0000 Subject: [PATCH] [IMP] base: improve log for wrong xpath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- odoo/tools/template_inheritance.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/odoo/tools/template_inheritance.py b/odoo/tools/template_inheritance.py index ad497d99bb7..33cedf7c12d 100644 --- a/odoo/tools/template_inheritance.py +++ b/odoo/tools/template_inheritance.py @@ -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