diff --git a/odoo/addons/base/models/ir_qweb.py b/odoo/addons/base/models/ir_qweb.py index 0fe81af01ad..8e2ef1f41a8 100644 --- a/odoo/addons/base/models/ir_qweb.py +++ b/odoo/addons/base/models/ir_qweb.py @@ -636,22 +636,21 @@ class IrQWeb(models.AbstractModel): string document that contains ``element``, and ``ref`` if the uniq reference of the template (id, t-name or template). - :param template: template identifier, name or etree + :param template: template identifier or etree :param options: used to compile the template (the dict available for the rendering is frozen) ``load`` (function) overrides the load method """ + assert template not in (False, None, ""), "template is required" + # template is an xml etree already if isinstance(template, etree._Element): element = template document = etree.tostring(template, encoding='unicode') ref = None - # template is xml as string - elif isinstance(template, str) and template.startswith('<'): - element = etree.fromstring(template) - document = template - ref = None + elif isinstance(template, str) and '<' in template: + raise ValueError('Inline templates must be passed as `etree` documents') # template is (id or ref) to a database stored template else: diff --git a/odoo/addons/base/tests/test_qweb.py b/odoo/addons/base/tests/test_qweb.py index 11957e67ca9..b3897c2699c 100644 --- a/odoo/addons/base/tests/test_qweb.py +++ b/odoo/addons/base/tests/test_qweb.py @@ -17,6 +17,7 @@ from odoo.tests.common import TransactionCase from odoo.addons.base.models.ir_qweb import QWebException, render from odoo.tools import misc, mute_logger from odoo.tools.json import scriptsafe as json_scriptsafe +from odoo.exceptions import MissingError unsafe_eval = eval @@ -1240,6 +1241,51 @@ class TestQWebBasic(TransactionCase): self.assertIn('Can not compile expression', error) self.assertIn('
', error) + def test_error_message_3(self): + # The format error tells the developer what to do. + template = '''