Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend function "delete_records_safely_by_xml_id" to delete also child records #278

Open
baguenth opened this issue Feb 10, 2022 · 0 comments

Comments

@baguenth
Copy link
Member

baguenth commented Feb 10, 2022

When applying function "delete_records_safely_by_xml_id" on views which are inherited by other views, we currently receive the following constraint error which lets the migration fail.

OpenUpgrade: Deleting record for XML-ID module.view
OpenUpgrade: Deleting record ir.ui.view#1234
odoo.sql_db: bad query: DELETE FROM ir_ui_view WHERE id IN (1234)ERROR: update or delete on table "ir_ui_view" violates foreign key constraint "ir_ui_view_inherit_id_fkey" on table "ir_ui_view"DETAIL: Key (id)=(1234) is still referenced from table "ir_ui_view".
Error deleting XML-ID module.view : ForeignKeyViolation('update or delete on table "ir_ui_view" violates foreign key constraint "ir_ui_view_inherit_id_fkey" on table "ir_ui_view"\nDETAIL: Key (id)=(1234) is still referenced from table "ir_ui_view".\n')
OpenUpgrade: XML-ID module.view changed to noupdate.

The current workaround is to first delete all the child records, which in fact is not a great solution since it is not really safe in terms of rollback capability etc.:

@openupgrade.migrate()
def migrate(env, version):
parent_id = env.ref("module.view")
env["ir.ui.view"].search([("inherit_id", "=", parent_id.id)]).unlink()
openupgrade.delete_records_safely_by_xml_id(
env,
[
"module.view",
],
)

I understand, that deleting all the child records is may not what everybody wants, therefore it should be optional, e.g. by passing an additional parameter "delete_childs" to "delete_records_safely_by_xml_id".

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

No branches or pull requests

1 participant