Skip to content

[FIX] util/record: remove model data of cascade records - #503

Open
hpr-odoo wants to merge 1 commit into
odoo:masterfrom
odoo-dev:master-remove-model_data-of-cascade-records-hpr
Open

[FIX] util/record: remove model data of cascade records#503
hpr-odoo wants to merge 1 commit into
odoo:masterfrom
odoo-dev:master-remove-model_data-of-cascade-records-hpr

Conversation

@hpr-odoo

@hpr-odoo hpr-odoo commented Aug 27, 2026

Copy link
Copy Markdown
Contributor
  • When records are deleted, cascade-linked records are also deleted.
    This may leave behind the ir_model_data entries in the database.
    This then triggers the records removal again when the ORM cleans up
    non-loaded references (after all end- scripts). This pollutes the logs
    with useless info.

  • before fix:

(Pdb) cr.execute("select count(*) from account_report_expression where report_line_id in (60, 61, 59, 57, 58, 56, 55)")
(Pdb) cr.fetchone()
(0,)
(Pdb) cr.execute("select count(*) from ir_model_data imd left join account_report_expression are on imd.res_id = are.id where model='account.report.expression' and are.id is null")
(Pdb) cr.fetchone()
(34,)
  • as a short note:
2026-08-27 12:26:05,543 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 80@account.report.expression (account_reports.unreconciled_last_statement_payments_forced_currency_amount)
2026-08-27 12:26:05,543 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 79@account.report.expression (account_reports.unreconciled_last_statement_payments_amount)
2026-08-27 12:26:05,544 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 78@account.report.expression (account_reports.unreconciled_last_statement_payments_currency)
2026-08-27 12:26:05,544 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 77@account.report.expression (account_reports.unreconciled_last_statement_payments_forced_currency_amount_currency)
2026-08-27 12:26:05,544 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 76@account.report.expression (account_reports.unreconciled_last_statement_payments_amount_currency)
2026-08-27 12:26:05,545 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 75@account.report.expression (account_reports.unreconciled_last_statement_payments_label)
2026-08-27 12:26:05,546 339679 INFO test_19 odoo.addons.base.models.ir_model: Deleting 74@account.report.expression (account_reports.unreconciled_last_statement_payments_date)
  • after fix:
(Pdb) cr.execute("select count(*) from account_report_expression where report_line_id in (60, 61, 59, 57, 58, 56, 55)")
(Pdb) cr.fetchone()
(0,)
(Pdb) cr.execute("select count(*) from ir_model_data imd left join account_report_expression are on imd.res_id = are.id where model='account.report.expression' and are.id is null")
(Pdb) cr.fetchone()
(0,)

@robodoo

robodoo commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Pull request status dashboard

@hpr-odoo
hpr-odoo force-pushed the master-remove-model_data-of-cascade-records-hpr branch 2 times, most recently from ce9d71c to efe4eb6 Compare August 27, 2026 12:00
@KangOl

KangOl commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

upgradeci retry with always only base

Comment thread src/util/records.py Outdated
Comment on lines +474 to +482
DELETE FROM ir_model_data
WHERE model = {fk_model}
AND res_id IN (SELECT id FROM {fk_tbl} WHERE {fk_col} IN %s)
""",
fk_model=sql.Literal(model_of_table(cr, fk_tbl)),
fk_tbl=sql.SQL(fk_tbl),
fk_col=sql.SQL(fk_col),
),
[ids],

@aj-fuentes aj-fuentes Aug 28, 2026

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.

Don't use format_query to format data, use instead the parameters of cr.execute/mogrify.
sql.Literal in format_query is always a code smell, as well as sql.SQL.
Fully qualify columns just in case.

Suggested change
DELETE FROM ir_model_data
WHERE model = {fk_model}
AND res_id IN (SELECT id FROM {fk_tbl} WHERE {fk_col} IN %s)
""",
fk_model=sql.Literal(model_of_table(cr, fk_tbl)),
fk_tbl=sql.SQL(fk_tbl),
fk_col=sql.SQL(fk_col),
),
[ids],
DELETE FROM ir_model_data d
WHERE d.model = %s
AND d.res_id IN (SELECT t.id FROM {fk_tbl} t WHERE t.{fk_col} IN %s)
""",
fk_tbl=fk_tbl,
fk_col=fk_col,
),
[model_of_table(cr, fk_tbl), ids],

@hpr-odoo hpr-odoo Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh my 🤦
yes, sql.SQL was there from my rough code so
Thank you for the review, Changes been updated 🫡

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for CI going to open a PR in upgrade soon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hello @aj-fuentes , Here is my patch to resolve the CI(runbot)?
Thank you

@hpr-odoo
hpr-odoo force-pushed the master-remove-model_data-of-cascade-records-hpr branch 4 times, most recently from 64efe38 to 0b25225 Compare August 31, 2026 09:07
- When records are deleted, cascade-linked records are also deleted.
- This may leave behind the ir_model_data entries in the database.
- This then triggers the records removal again when the ORM cleans up
non-loaded references (after all end- scripts). This pollutes the logs
with useless info.

- before fix:
```py
(Pdb) cr.execute("select count(*) from account_report_expression where report_line_id in (60, 61, 59, 57, 58, 56, 55)")
(Pdb) cr.fetchone()
(0,)
(Pdb) cr.execute("select count(*) from ir_model_data imd left join account_report_expression are on imd.res_id = are.id where model='account.report.expression' and are.id is null")
(Pdb) cr.fetchone()
(34,)
```
- after fix:
```py
(Pdb) cr.execute("select count(*) from account_report_expression where report_line_id in (60, 61, 59, 57, 58, 56, 55)")
(Pdb) cr.fetchone()
(0,)
(Pdb) cr.execute("select count(*) from ir_model_data imd left join account_report_expression are on imd.res_id = are.id where model='account.report.expression' and are.id is null")
(Pdb) cr.fetchone()
(0,)
```
@hpr-odoo
hpr-odoo force-pushed the master-remove-model_data-of-cascade-records-hpr branch from 0b25225 to 2e15e41 Compare August 31, 2026 09:08
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