From 1bceb01ff4ff3a955bbe2a69ed4a258b1517a134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Tue, 8 Aug 2023 13:32:08 +0000 Subject: [PATCH] [FIX] website: fix unlink page with ir.rule Issue ===== The previous commit forced consistency between `check_access_rule` and `_apply_ir_rule`. Now the parent model `ir.rule` (via inherited) is also checked before the unlinking (`check_access_rule("unlink")`). The `website.page` unlink override sometimes calls `unlink` on its parent view and because view_id has `ondelete="cascade"`, it will actually deletes the `website.page` itself. Then calling to `super().unlink()` with self will raise a MissingError. Fix === Batch the old logic and remove already unlinked record from `self` before calling `super`. closes odoo/odoo#125916 Signed-off-by: Raphael Collet --- addons/website/models/website_page.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/website/models/website_page.py b/addons/website/models/website_page.py index c749b7179f6..99af9e803ba 100644 --- a/addons/website/models/website_page.py +++ b/addons/website/models/website_page.py @@ -139,17 +139,16 @@ class Page(models.Model): # When a website_page is deleted, the ORM does not delete its # ir_ui_view. So we got to delete it ourself, but only if the # ir_ui_view is not used by another website_page. - for page in self: - # Other pages linked to the ir_ui_view of the page being deleted (will it even be possible?) - pages_linked_to_iruiview = self.search( - [('view_id', '=', page.view_id.id), ('id', '!=', page.id)] - ) - if not pages_linked_to_iruiview and not page.view_id.inherit_children_ids: - # If there is no other pages linked to that ir_ui_view, we can delete the ir_ui_view - page.view_id.unlink() + views_to_delete = self.view_id.filtered( + lambda v: v.page_ids <= self and not v.inherit_children_ids + ) + # Rebind self to avoid unlink already deleted records from `ondelete="cascade"` + self = self - views_to_delete.page_ids + views_to_delete.unlink() + # Make sure website._get_menu_ids() will be recomputed self.env.registry.clear_cache() - return super(Page, self).unlink() + return super().unlink() def write(self, vals): for page in self: