From 56d1a1e475194f16eca3fc442801058a2198af6a Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 22 Oct 2024 08:24:55 +0200 Subject: [PATCH 1/2] [FIX] auditlog: registry propagation When a new auditlog rule is added / modified / deleted, all workers need to be notified of the change. This is done through registry signaling. The previous code was not using the proper level of signaling resulting in workers not being aware of the changes and not implementing the correct auditlog rules, because they had only invalidated their cache and not reloaded the registry. We fix this by using the same signaling as implemented in `base_automation` which sets the the registry_invalidated field of env.registry to True to cause a full registry reload. --- auditlog/models/rule.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index bcf7cf9bf..333208b05 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -3,7 +3,7 @@ import copy -from odoo import _, api, fields, models, modules +from odoo import _, api, fields, models from odoo.exceptions import UserError FIELDS_BLACKLIST = [ @@ -223,7 +223,7 @@ class AuditlogRule(models.Model): delattr(type(model_model), "auditlog_ruled_%s" % method) updated = True if updated: - modules.registry.Registry(self.env.cr.dbname).signal_changes() + self._update_registry() @api.model_create_multi def create(self, vals_list): @@ -236,7 +236,7 @@ class AuditlogRule(models.Model): new_records = super().create(vals_list) updated = [record._register_hook() for record in new_records] if any(updated): - modules.registry.Registry(self.env.cr.dbname).signal_changes() + self._update_registry() return new_records def write(self, vals): @@ -248,7 +248,7 @@ class AuditlogRule(models.Model): vals.update({"model_name": model.name, "model_model": model.model}) res = super().write(vals) if self._register_hook(): - modules.registry.Registry(self.env.cr.dbname).signal_changes() + self._update_registry() return res def unlink(self): @@ -735,3 +735,9 @@ class AuditlogRule(models.Model): if isinstance(fieldvalue, models.BaseModel) and not fieldvalue: vals[fieldname] = False return vals_list + + def _update_registry(self): + """Update the registry after a modification on automation rules.""" + if self.env.registry.ready and not self.env.context.get("import_file"): + # notify other workers + self.env.registry.registry_invalidated = True From 5d2afc0325b1f22a9301ee7f88cd16497f1b3282 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 22 Oct 2024 08:52:25 +0200 Subject: [PATCH 2/2] fixup! [FIX] auditlog: registry propagation --- auditlog/models/rule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 333208b05..42297e384 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -737,7 +737,8 @@ class AuditlogRule(models.Model): return vals_list def _update_registry(self): - """Update the registry after a modification on automation rules.""" + """Force a registry reload after rule change""" + # this code comes from `base_automation` which has a similar need if self.env.registry.ready and not self.env.context.get("import_file"): # notify other workers self.env.registry.registry_invalidated = True