[FIX] util/record: remove model data of cascade records - #503
Open
hpr-odoo wants to merge 1 commit into
Open
Conversation
Contributor
hpr-odoo
force-pushed
the
master-remove-model_data-of-cascade-records-hpr
branch
2 times, most recently
from
August 27, 2026 12:00
ce9d71c to
efe4eb6
Compare
Contributor
|
upgradeci retry with always only base |
aj-fuentes
reviewed
Aug 28, 2026
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], |
Contributor
There was a problem hiding this comment.
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], |
Contributor
Author
There was a problem hiding this comment.
Oh my 🤦
yes, sql.SQL was there from my rough code so
Thank you for the review, Changes been updated 🫡
Contributor
Author
There was a problem hiding this comment.
for CI going to open a PR in upgrade soon
Contributor
Author
There was a problem hiding this comment.
Hello @aj-fuentes , Here is my patch to resolve the CI(runbot)?
Thank you
hpr-odoo
force-pushed
the
master-remove-model_data-of-cascade-records-hpr
branch
4 times, most recently
from
August 31, 2026 09:07
64efe38 to
0b25225
Compare
- 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
force-pushed
the
master-remove-model_data-of-cascade-records-hpr
branch
from
August 31, 2026 09:08
0b25225 to
2e15e41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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: