Skip to content

[FIX] pg: rename m2m field meta data - #343

Open
jjmaksoud wants to merge 1 commit into
odoo:masterfrom
odoo-dev:master-rename-m2m-rels-maji
Open

jjmaksoud wants to merge 1 commit into
odoo:masterfrom
odoo-dev:master-rename-m2m-rels-maji

Conversation

@jjmaksoud

Copy link
Copy Markdown
Contributor

When renaming a model and updating related m2m fields, the relation table and its columns are renamed but only manual fields meta data is updated, assuming that base fields will be updated when the module loads.
The custom modules meta data should also be updated if the tables were updated.

upg-3176133

@robodoo

robodoo commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Pull request status dashboard

@jjmaksoud

Copy link
Copy Markdown
Contributor Author

upgradeci retry with always only base

@jjmaksoud
jjmaksoud requested review from a team and Pirols October 20, 2025 13:03

@aj-fuentes aj-fuentes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better check if there isn't any xmlid for the field under the available modules (standard_modules usual trick)

@jjmaksoud
jjmaksoud force-pushed the master-rename-m2m-rels-maji branch 2 times, most recently from eef47dd to 220fed7 Compare October 31, 2025 14:59
Comment thread src/util/pg.py
Comment thread src/util/pg.py Outdated
Comment thread src/util/pg.py Outdated
Comment thread src/util/pg.py Outdated
Comment thread src/util/pg.py Outdated
@jjmaksoud
jjmaksoud force-pushed the master-rename-m2m-rels-maji branch from a25ae4f to da2dbe1 Compare August 28, 2026 08:15
Comment thread src/util/pg.py Outdated
@jjmaksoud
jjmaksoud force-pushed the master-rename-m2m-rels-maji branch from da2dbe1 to 1cb75bf Compare September 7, 2026 13:29
When renaming a model and updating related m2m fields,
the relation table and its columns are renamed but only
manual fields meta data is updated, assuming that base
fields will be updated when the module loads.
The custom modules meta data should also be updated if
the tables were updated.
@jjmaksoud
jjmaksoud force-pushed the master-rename-m2m-rels-maji branch from 1cb75bf to 24a74e0 Compare September 17, 2026 08:50
Comment thread src/util/pg.py
Comment on lines -1722 to +1732
UPDATE ir_model_fields
UPDATE ir_model_fields f
SET relation_table = %s
WHERE relation_table = %s
AND state = 'manual'
FROM ir_model_data d
WHERE f.relation_table = %s
AND (
f.state = 'manual'
OR (d.model = 'ir.model.fields'
AND d.res_id = f.id
AND d.module NOT IN %s)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will update row multiple times.
Better use a CTE.

Suggested change
UPDATE ir_model_fields
UPDATE ir_model_fields f
SET relation_table = %s
WHERE relation_table = %s
AND state = 'manual'
FROM ir_model_data d
WHERE f.relation_table = %s
AND (
f.state = 'manual'
OR (d.model = 'ir.model.fields'
AND d.res_id = f.id
AND d.module NOT IN %s)
)
WITH _f AS (
SELECT f.id
FROM ir_model_fields f
LEFT JOIN ir_model_data d
ON d.model = 'ir.model.fields'
AND d.res_id = f.id
AND d.module NOT IN %s
WHERE f.relation_table = %s
AND (d.id IS NOT NULL OR f.state = 'manual')
GROUP BY f.id
)
UPDATE ir_model_fields
SET relation_table = %s
FROM _f
WHERE _f.if = ir_model_fields.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants