From d0403406898878443f522693c70eab763a938161 Mon Sep 17 00:00:00 2001 From: vval Date: Thu, 11 Sep 2025 13:32:14 +0000 Subject: [PATCH] [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) --- src/util/pg.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/util/pg.py b/src/util/pg.py index 901fcb5e9..1fb6d6a7c 100644 --- a/src/util/pg.py +++ b/src/util/pg.py @@ -1465,6 +1465,28 @@ def update_m2m_tables(cr, old_table, new_table, ignored_m2ms=()): del_action=SQLStr("RESTRICT") if on_delete == "r" else SQLStr("CASCADE"), ) cr.execute(query) + + cr.execute( + """ + UPDATE ir_model_fields + SET column1 = %s + WHERE relation_table = %s + AND column1 = %s + AND state = 'manual' + """, + [new_col, m2m_table, old_col], + ) + cr.execute( + """ + UPDATE ir_model_fields + SET column2 = %s + WHERE relation_table = %s + AND column2 = %s + AND state = 'manual' + """, + [new_col, m2m_table, old_col], + ) + _logger.info("Renamed m2m column of table %s from %s to %s", m2m_table, old_col, new_col)