From ea9d6649eeb58a6413fc7001acbda80e179da0d8 Mon Sep 17 00:00:00 2001 From: Saurabh Choraria Date: Thu, 27 Jul 2023 12:36:59 +0000 Subject: [PATCH] [FIX] base: handle error when editing comment in view's architecture Currently, When the user is adding a double hyphen or space or anything within a comment in a view's architecture and tries to save the view, then an error occurs. To reproduce the issue: 1. Go to Settings > Technical > Views > open a view. 2. In View Architecture comment out a line. 3. Add a double hyphen or space or anything within the comment. 4. Then save manually, the error will occur. To solve this issue the error has been handled using a try-except block in 'parse_html' method. sentry-4306359331 closes odoo/odoo#132267 X-original-commit: ba6f90fac142ae53995f4fce4b75799e61b95b6c Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Saurabh Choraria (sauc) --- odoo/addons/base/i18n/base.pot | 10 ++++++++++ odoo/tools/translate.py | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index a172bfc9f3c..7c9137a7e96 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -14994,6 +14994,16 @@ msgstr "" msgid "Error message returned when the constraint is violated." msgstr "" +#. module: base +#. odoo-python +#: code:addons/translate.py:0 +#, python-format +msgid "" +"Error while parsing view:\n" +"\n" +"%s" +msgstr "" + #. module: base #. odoo-python #: code:addons/base/models/ir_ui_view.py:0 diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 454015369cb..246cf188d26 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -26,6 +26,7 @@ from lxml import etree, html from psycopg2.extras import Json import odoo +from odoo.exceptions import UserError from odoo.modules.module import get_resource_path from . import config, pycompat from .misc import file_open, get_iso_codes, SKIPPED_ELEMENT_TYPES @@ -293,7 +294,11 @@ def serialize_xml(node): _HTML_PARSER = etree.HTMLParser(encoding='utf8') def parse_html(text): - return html.fragment_fromstring(text, parser=_HTML_PARSER) + try: + parse = html.fragment_fromstring(text, parser=_HTML_PARSER) + except TypeError as e: + raise UserError(_("Error while parsing view:\n\n%s") % e) from e + return parse def serialize_html(node): return etree.tostring(node, method='html', encoding='unicode')