Skip to content

Commit

Permalink
[FIX] auditlog: registry propagation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gurneyalex committed Oct 22, 2024
1 parent 6bc276d commit b7cb436
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _revert_methods(self):
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):
Expand All @@ -236,7 +236,7 @@ def create(self, vals_list):
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):
Expand All @@ -248,7 +248,7 @@ def write(self, vals):
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):
Expand Down Expand Up @@ -735,3 +735,9 @@ def _update_vals_list(self, vals_list):
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

0 comments on commit b7cb436

Please sign in to comment.