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

[FIX] pg: rename m2m field meta data#343
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 from 230c1ff to eef47dd Compare October 31, 2025 14:57
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 eef47dd to 220fed7 Compare October 31, 2025 14:59
Comment thread src/util/pg.py
Comment on lines +1484 to +1489
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.

Suggested change
AND (
f.state = 'manual'
OR d.model = 'ir.model.fields'
AND d.res_id = f.id
AND d.module NOT IN %s
)
AND ( f.state = 'manual'
OR (d.model = 'ir.model.fields'
AND d.res_id = f.id
AND d.module NOT IN %s)
)

Even with formatted this query looks hard to understand. Wouldn't it be better if we just do a cte?

WITH to_upd (
   SELECT f.id
     FROM ir_model_fields f
     JOIN ir_model_data d
       ON d.model = 'ir.model.fields'
      AND d.res_id = f.id
    WHERE f.relation_table = %s
       AND (  f.state = 'manual'
           OR d.module NOT IN %s)
) UPDATE ...

@aj-fuentes
aj-fuentes requested a review from KangOl November 4, 2025 15:18
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.

3 participants