[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@6932714200

closes odoo/odoo#161583

X-original-commit: f2765d2cab5671a010404c36842bf1b4c4d6350b
Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
This commit is contained in:
Paul Morelle
2024-04-12 11:26:47 +00:00
committed by Christophe Simonis
parent 351f894ed9
commit 6788f43d6b
+5
View File
@@ -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('/')