From 6788f43d6b487ce07f8678cadcd06f90e417dffa Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Tue, 27 Feb 2024 17:49:10 +0100 Subject: [PATCH] [IMP] base: avoid infinite loops in _update_category When updating the categories, if by any chance there is a loop in the category hierarchy, the current code was falling into an infinite loop. With this commit, the graph loop is broken by clearing a parent_id, and if the resulting module category path is wrong, a clean new one will be recreated anyway. This allows unblocking uncomfortable situations where people cannot update the modules list any more. In 15.0, [a check][1] has been introduced to prevent the existence of recursive categories, but as it is a python check it doesn't prevent corrupted data to remain corrupted. OPW-3704007 Related to odoo/upgrade#5574 [1]: odoo/odoo@6932714200d158a21bf10b90b2f71fa5cae0b13f closes odoo/odoo#161583 X-original-commit: f2765d2cab5671a010404c36842bf1b4c4d6350b Signed-off-by: Christophe Simonis (chs) --- odoo/addons/base/models/ir_module.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py index 5cfb3156f09..d1736f5b036 100644 --- a/odoo/addons/base/models/ir_module.py +++ b/odoo/addons/base/models/ir_module.py @@ -812,9 +812,14 @@ class Module(models.Model): def _update_category(self, category='Uncategorized'): current_category = self.category_id + seen = set() current_category_path = [] while current_category: current_category_path.insert(0, current_category.name) + seen.add(current_category.id) + if current_category.parent_id.id in seen: + current_category.parent_id = False + _logger.warning('category %r ancestry loop has been detected and fixed', current_category) current_category = current_category.parent_id categs = category.split('/')