Skip to content

Commit 946deba

Browse files
committed
[FIX] util/records: do not perform callback if xmlid is gone
Before acceff5 we returned early if the xmlid passed to `if_unchanged` was missing. After that commit was merged we always execute the `callback`. This is problematic when the callback is `update_record_from_xml`. It will create records even if they are in `forcecreate=0`. closes #203 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 0ad717f commit 946deba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/util/records.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,12 @@ def is_changed(cr, xmlid, interval="1 minute"):
568568
* Have been updated in an upgrade preceding the current one
569569
* Have not been updated in the current upgrade
570570
571+
If the `xmlid` doesn't exist in the DB this function returns ``None``.
572+
571573
:param str xmlid: `xmlid` of the record to check
572574
:param str interval: SQL interval, a record is considered as changed if
573575
`write_date > create_date + interval`
574-
:rtype: bool
576+
:rtype: bool or None
575577
"""
576578
assert "." in xmlid
577579
module, _, name = xmlid.partition(".")
@@ -620,7 +622,10 @@ def if_unchanged(cr, xmlid, callback, interval="1 minute", **kwargs):
620622
:param str interval: interval after `create_date` on which a record is considered as
621623
_changed_, see :func:`~odoo.upgrade.util.misc.is_changed`
622624
"""
623-
if not is_changed(cr, xmlid, interval=interval):
625+
changed = is_changed(cr, xmlid, interval=interval)
626+
if changed is None:
627+
return
628+
if changed is False:
624629
callback(cr, xmlid, **kwargs)
625630
else:
626631
force_noupdate(cr, xmlid, noupdate=True)

0 commit comments

Comments
 (0)