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.
gurneyalex committed Oct 22, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
BridgeAR Ruben Bridgewater
1 parent 6bc276d commit 56d1a1e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
@@ -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 @@ 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):
@@ -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):
@@ -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):
@@ -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

Check warning on line 743 in auditlog/models/rule.py

Codecov / codecov/patch

auditlog/models/rule.py#L743

Added line #L743 was not covered by tests

0 comments on commit 56d1a1e

Please sign in to comment.