Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/base/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,11 @@ def test_replace_record_references_batch__uniqueness(self):
[count] = self.env.cr.fetchone()
self.assertEqual(count, 1)

@mute_logger("odoo.upgrade.util.records")
def test_replace_record_references_batch__idem_mapping(self):
# This logs a warning but shouldn't fail
util.replace_record_references_batch(self.env.cr, {1: 1, 2: 2}, "res.country")

def _prepare_test_delete_unused(self):
def create_cat():
name = f"test_{uuid.uuid4().hex}"
Expand Down
3 changes: 3 additions & 0 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ def replace_record_references_batch(cr, id_mapping, model_src, model_dst=None, r
if same_ids:
_logger.warning("Replace references in model `%s`, ignoring same-id mapping `%s`", model_src, same_ids)
id_mapping = {k: v for k, v in id_mapping.items() if k != v}
if not id_mapping:
_logger.warning("Nothing to replace in model `%s`, ignoring empty mapping", model_src)
return

assert id_mapping
assert all(isinstance(v, int) and isinstance(k, int) for k, v in id_mapping.items())
Expand Down