Skip to content
Snippets Groups Projects
Commit 58e463e7 authored by Karnav Sojitra's avatar Karnav Sojitra
Browse files

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

Signed-off-by: default avatarAchraf Ben Azzouz (abz) <abz@odoo.com>
parent bfc83df7
No related branches found
No related tags found
No related merge requests found
...@@ -14898,6 +14898,12 @@ msgstr "" ...@@ -14898,6 +14898,12 @@ msgstr ""
msgid "Invalid 'group by' parameter" msgid "Invalid 'group by' parameter"
msgstr "" msgstr ""
   
#. module: base
#: code:addons/template_inheritance.py:0
#, python-format
msgid "Invalid Expression while parsing xpath %r"
msgstr ""
#. module: base #. module: base
#: code:addons/base/models/ir_default.py:0 #: code:addons/base/models/ir_default.py:0
#, python-format #, python-format
......
...@@ -7,6 +7,7 @@ import logging ...@@ -7,6 +7,7 @@ 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
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -56,9 +57,8 @@ def locate_node(arch, spec): ...@@ -56,9 +57,8 @@ def locate_node(arch, spec):
expr = spec.get('expr') expr = spec.get('expr')
try: try:
xPath = etree.ETXPath(expr) xPath = etree.ETXPath(expr)
except etree.XPathSyntaxError: except etree.XPathSyntaxError as e:
_logger.error("XPathSyntaxError while parsing xpath %r", expr) raise ValidationError(_("Invalid Expression while parsing xpath %r", expr)) from e
raise
nodes = xPath(arch) 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':
......
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