Skip to content

Commit 7b97661

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)
1 parent b910e43 commit 7b97661

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/util/pg.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,22 @@ 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 = CASE WHEN column1 = %(old_col)s THEN %(new_col)s ELSE column1 END,
1473+
column2 = CASE WHEN column2 = %(old_col)s THEN %(new_col)s ELSE column2 END
1474+
WHERE relation_table = %(m2m_table)s
1475+
AND (column1 = %(old_col)s OR column2 = %(old_col)s)
1476+
""",
1477+
{
1478+
"old_col": old_col,
1479+
"new_col": new_col,
1480+
"m2m_table": m2m_table,
1481+
},
1482+
)
1483+
14681484
_logger.info("Renamed m2m column of table %s from %s to %s", m2m_table, old_col, new_col)
14691485

14701486

0 commit comments

Comments
 (0)