Skip to content

[FIX] delete_records_safely_by_xml_id childs by record._name - #455

Closed
sergiocorato wants to merge 1 commit into
OCA:masterfrom
efatto:fix-delete_records_safely_by_xml_id-childs-by-record-_name
Closed

sergiocorato wants to merge 1 commit into
OCA:masterfrom
efatto:fix-delete_records_safely_by_xml_id-childs-by-record-_name

Conversation

@sergiocorato

Copy link
Copy Markdown

No description provided.

@sergiocorato
sergiocorato marked this pull request as ready for review July 19, 2026 16:21
@hbrunn

hbrunn commented Sep 16, 2026

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch master-ocabot-merge-pr-455-by-hbrunn-bump-nobump, awaiting test results.

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the solution is to restrict that search to views, as if not, they won't have that field anyway. And document everything. Another option is to include the parent field name as optional.

@@ -3636,7 +3636,7 @@ def delete_records_safely_by_xml_id(env, xml_ids, delete_childs=False):
if not record:
continue
if delete_childs:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if delete_childs:
if delete_childs and record._name == "ir.ui.view":

@hbrunn

hbrunn commented Sep 16, 2026

Copy link
Copy Markdown
Member

@pedrobaeza I disagree. any model that supports the child_of operator can profit from this. note this originates from a real use case in OCA/OpenUpgrade#5719 (comment)

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

I think @pedrobaeza is concerned with inherit_id. Not every model has that field.

@hbrunn

hbrunn commented Sep 16, 2026

Copy link
Copy Markdown
Member

ahh right. then this should indeed do inherit_id for ir.ui.view and id for the rest

@pedrobaeza

Copy link
Copy Markdown
Member

Not id, but the field expressing the parent-child relation (parent_id or whatever). That's what inherit_id means in this context.

@hbrunn

hbrunn commented Sep 16, 2026

Copy link
Copy Markdown
Member

then we seem to differ about what this should do. for a generic model with a parent_id field, and entries

id: 42
parent_id: None

id: 43
parent_id: 42

I expect delete...xml_id(['xml_id_of_record_42'], delete_childs=True) to delete the record with id 43

@pedrobaeza

Copy link
Copy Markdown
Member

Yeah, that's it, both 42 and 43 will be removed. You point the parent record, and all the childrens recursively are removed. What I'm saying is that the inherit_id field is the parent many2one reference.

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

and all the childrens recursively are removed

Not exactly. To be truly recursive, the method delete_records_safely_by_xml_id should call itself.

@pedrobaeza

Copy link
Copy Markdown
Member

Then the implementation is half-baked in my opinion, as I understand the use case about removing "this view and any descendant". Removing a view (or other record), and only the children may give error.

@hbrunn

hbrunn commented Sep 19, 2026

Copy link
Copy Markdown
Member

I'm closing this in favor of the somewhat more advanced #466

@hbrunn hbrunn closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants