Skip to content

Commit ce74d4a

Browse files
committed
[IMP] util.update_record_from_xml: ensure the xmlid exists
It allow catching typos. Typos and other issues fixed in odoo/upgrade#5524 Part-of: #36
1 parent d97d115 commit ce74d4a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/util/records.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ def __update_record_from_xml(
771771
if cr.rowcount:
772772
model, res_id, noupdate = cr.fetchone()
773773
elif not force_create:
774+
_logger.warning("Record %r not found in database. Skip update.", xmlid)
774775
return
775776
else:
776777
# The xmlid doesn't already exists, nothing to reset
@@ -796,6 +797,7 @@ def __update_record_from_xml(
796797

797798
manifest = get_manifest(from_module)
798799
template = False
800+
found = False
799801
extra_references = []
800802

801803
def add_ref(ref):
@@ -810,6 +812,7 @@ def add_ref(ref):
810812
with file_open(os.path.join(from_module, f)) as fp:
811813
doc = lxml.etree.parse(fp)
812814
for node in doc.xpath(xpath):
815+
found = True
813816
parent = node.getparent()
814817
new_root[0].append(node)
815818

@@ -831,6 +834,10 @@ def add_ref(ref):
831834
for ref_match in re.finditer(r"\bref\((['\"])(.*?)\1\)", eval_node.get("eval")):
832835
add_ref(ref_match.group(2))
833836

837+
if not found:
838+
suffix = " in %r module" % from_module if from_module != module else ""
839+
raise ValueError("Cannot find %r%s" % (xmlid, suffix))
840+
834841
done_refs.add(xmlid)
835842
for ref in extra_references:
836843
if ref in done_refs:

0 commit comments

Comments
 (0)