Skip to content

Commit 5df33e7

Browse files
committed
[IMP] util/records: improve mapping checks when replacing references
We perform some DELETEs in `replace_record_references_batch` as a cleanup step. Thus it is better to ensure the mapping always change the id. Example: https://github.com/odoo/upgrade-util/blob/dced6e030db111fab9446b323434e4c2e16bdd62/src/util/records.py#L1723 Part-of: #243 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent dced6e0 commit 5df33e7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/util/records.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,18 +1458,22 @@ def replace_record_references_batch(cr, id_mapping, model_src, model_dst=None, r
14581458
:param list(str) ignores: list of **table** names to skip when updating the referenced
14591459
values
14601460
"""
1461-
assert id_mapping
1462-
assert all(isinstance(v, int) and isinstance(k, int) for k, v in id_mapping.items())
1463-
14641461
_validate_model(model_src)
14651462
if model_dst is None:
14661463
model_dst = model_src
14671464
else:
14681465
_validate_model(model_dst)
14691466

1467+
if model_src == model_dst:
1468+
same_ids = {k: v for k, v in id_mapping.items() if k == v}
1469+
if same_ids:
1470+
_logger.warning("Replace references in model `%s`, ignoring same-id mapping `%s`", model_src, same_ids)
1471+
id_mapping = {k: v for k, v in id_mapping if k != v}
1472+
1473+
assert id_mapping
1474+
assert all(isinstance(v, int) and isinstance(k, int) for k, v in id_mapping.items())
1475+
14701476
id_update = any(k != v for k, v in id_mapping.items())
1471-
nop = (not id_update) and (model_src == model_dst)
1472-
assert nop is False
14731477

14741478
ignores = [_validate_table(table) for table in ignores]
14751479
if not replace_xmlid:

0 commit comments

Comments
 (0)