Skip to content

Commit 48de3cc

Browse files
committed
[FIX] util.update_record_from_xml: stricter XPath expression
Only select elements known to define a records. When building the XML tree that will be loaded, we use the `.append()` which actually *move* the node. The previous XPath expression matched any element having a corresponding `id` attribute. This conditions lead to a situation where the wanted record loose any element having a matching `id`. As show by the added test, updating the `web.login` template lead to loading the following XML file: ```xml <openerp><data> <template id="web.login"> <...> </template> <input type="text" name="login" id="login"/> </data></openerp> ``` Given that unknown tags are ignored, this error was silent. Part of odoo/upgrade#5267 Courtesy-of: Arnaud Baes <[email protected]> Courtesy-of: Paul Morelle <[email protected]> Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 3f1f830 commit 48de3cc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/base/tests/test_util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,18 @@ def test_update_record_from_xml__from_module(self):
757757
# web.layout should NOT have been updated
758758
self.assertEqual(layout.name, new_name)
759759

760+
def test_update_record_from_xml_bad_match(self):
761+
cr = self.env.cr
762+
if not util.module_installed(cr, "web"):
763+
self.skip()
764+
765+
xmlid = "web.login"
766+
util.update_record_from_xml(cr, xmlid)
767+
768+
arch = self.env.ref(xmlid).arch_db
769+
tree = etree.fromstring(arch)
770+
self.assertIsNotNone(tree.find(".//input[@id='login']"))
771+
760772
def test_ensure_xmlid_match_record(self):
761773
cr = self.env.cr
762774
tx1 = self.env["res.currency"].create({"name": "TX1", "symbol": "TX1"})

src/util/records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def update_record_from_xml(
756756
if module == from_module
757757
else "@id='{module}.{name}'".format(module=module, name=name)
758758
)
759-
xpath = "//*[{}]".format(id_match)
759+
xpath = "//*[self::act_window or self::menuitem or self::record or self::report or self::template][{}]".format(id_match) # fmt: skip
760760

761761
# use a data tag inside openerp tag to be compatible with all supported versions
762762
new_root = lxml.etree.fromstring("<openerp><data/></openerp>")

0 commit comments

Comments
 (0)