Skip to content

Commit

Permalink
Merge pull request #265 from Tecnativa/delete_records_safely_by_xml_i…
Browse files Browse the repository at this point in the history
…d-mark_no_update

[IMP] delete_records_safely_by_xml_id: Mark as noupdate failed ones
  • Loading branch information
pedrobaeza authored Dec 12, 2021
2 parents 9738409 + fffada8 commit 4c9ecad
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,10 @@ def delete_records_safely_by_xml_id(env, xml_ids):
"""This removes in the safest possible way the records whose XML-IDs are
passed as argument.
If not possible to be removed, and the record is an updatable one
(noupdate=0), it's switched to noupdate=1, for avoiding a later error when
Odoo performs the regular update cleanup and trying to remove it as well.
:param xml_ids: List of XML-ID string identifiers of the records to remove.
"""
for xml_id in xml_ids:
Expand All @@ -2559,6 +2563,13 @@ def delete_records_safely_by_xml_id(env, xml_ids):
safe_unlink(record, do_raise=True)
except Exception as e:
logger.info('Error deleting XML-ID %s: %s', xml_id, repr(e))
module, name = xml_id.split('.')
imd = env["ir.model.data"].search(
[("module", "=", module), ("name", "=", name)]
)
if not imd.noupdate:
imd.noupdate = True
logger.info("XML-ID %s changed to noupdate.", xml_id)


def chunked(records, single=True):
Expand Down

0 comments on commit 4c9ecad

Please sign in to comment.