[FIX] tools: raise validation error while invalid expression
When the user tries to modify the view with an invalid xpath expression, an XPathSyntaxError traceback will appear. Steps to produce: 1. Install the Accounting module. 2. Settings > Technical > UI > Views > Open any view 3. Invalidate expr syntax and try to save, thus an error will be generated. Error: XPathSyntaxError: Invalid expression This commit handles XPathSyntaxError by raising ValidationError instead of a traceback. sentry-4377014622 closes odoo/odoo#139435 X-original-commit: 2af583d0b803b3334b871002e447d3211eb09bc2 Signed-off-by: Achraf Ben Azzouz (abz) <abz@odoo.com>
This commit is contained in:
committed by
smna-odoo
parent
6637f1a4ab
commit
2d55340797
@@ -18238,6 +18238,12 @@ msgstr ""
|
||||
msgid "Invalid 'group by' parameter"
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#: code:addons/template_inheritance.py:0
|
||||
#, python-format
|
||||
msgid "Invalid Expression while parsing xpath %r"
|
||||
msgstr ""
|
||||
|
||||
#. module: base
|
||||
#: code:addons/base/models/ir_default.py:0
|
||||
#, python-format
|
||||
|
||||
@@ -8,6 +8,7 @@ import re
|
||||
|
||||
from odoo.tools.translate import _
|
||||
from odoo.tools import SKIPPED_ELEMENT_TYPES, html_escape
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
RSTRIP_REGEXP = re.compile(r'\n[ \t]*$')
|
||||
@@ -74,9 +75,8 @@ def locate_node(arch, spec):
|
||||
expr = spec.get('expr')
|
||||
try:
|
||||
xPath = etree.ETXPath(expr)
|
||||
except etree.XPathSyntaxError:
|
||||
_logger.error("XPathSyntaxError while parsing xpath %r", expr)
|
||||
raise
|
||||
except etree.XPathSyntaxError as e:
|
||||
raise ValidationError(_("Invalid Expression while parsing xpath %r", expr)) from e
|
||||
nodes = xPath(arch)
|
||||
return nodes[0] if nodes else None
|
||||
elif spec.tag == 'field':
|
||||
|
||||
Reference in New Issue
Block a user