Skip to content

Commit 85c5a6c

Browse files
committed
[FIX] util/pg: fix rename_model with m2m fields
In the case of renamed model being referenced in a many2many table (for having or being referenced in a m2m field), related `ir_model_fields.column1` (and 2) aren't updated. However, the m2m tables column names themselves are properly updated. This lead to an error because the `column1` is referring to a column whose name is already overwritten, and to a crash because the returned foreign keys list is empty but accessed at [0]. [tbg](https://upgrade.odoo.com/odoo/tbg/2156) closes #319 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 87c3e7e commit 85c5a6c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/util/pg.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,28 @@ def update_m2m_tables(cr, old_table, new_table, ignored_m2ms=()):
14651465
del_action=SQLStr("RESTRICT") if on_delete == "r" else SQLStr("CASCADE"),
14661466
)
14671467
cr.execute(query)
1468+
1469+
cr.execute(
1470+
"""
1471+
UPDATE ir_model_fields
1472+
SET column1 = %s
1473+
WHERE relation_table = %s
1474+
AND column1 = %s
1475+
AND state = 'manual'
1476+
""",
1477+
[new_col, m2m_table, old_col],
1478+
)
1479+
cr.execute(
1480+
"""
1481+
UPDATE ir_model_fields
1482+
SET column2 = %s
1483+
WHERE relation_table = %s
1484+
AND column2 = %s
1485+
AND state = 'manual'
1486+
""",
1487+
[new_col, m2m_table, old_col],
1488+
)
1489+
14681490
_logger.info("Renamed m2m column of table %s from %s to %s", m2m_table, old_col, new_col)
14691491

14701492

0 commit comments

Comments
 (0)