[FIX] base: discard clear_cache on method res_users.has_group
Overriding method has_group() in some extension of model 'res.users' is not possible because of code invoking model.has_group.clear_cache(). As clear_cache() is no longer invoked on ormcached methods, we can simply replace the code by a global cache invalidation. In this case, it is not even necessary, since method call_cache_clearing_methods() does it already. closes odoo/odoo#95071 X-original-commit: 2dc80fe49ec2cb11e65465d4616b9bbb136bf6ab Signed-off-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
committed by
Raphael Collet
parent
3cd17a735b
commit
ee689a5945
@@ -215,7 +215,6 @@ class Groups(models.Model):
|
||||
# DLE P139
|
||||
if self.ids:
|
||||
self.env['ir.model.access'].call_cache_clearing_methods()
|
||||
self.env['res.users'].has_group.clear_cache(self.env['res.users'])
|
||||
return super(Groups, self).write(vals)
|
||||
|
||||
|
||||
@@ -910,8 +909,6 @@ class Users(models.Model):
|
||||
(SELECT res_id FROM ir_model_data WHERE module=%s AND name=%s)""",
|
||||
(self._uid, module, ext_id))
|
||||
return bool(self._cr.fetchone())
|
||||
# for a few places explicitly clearing the has_group cache
|
||||
has_group.clear_cache = _has_group.clear_cache
|
||||
|
||||
def _action_show(self):
|
||||
"""If self is a singleton, directly access the form view. If it is a recordset, open a tree view"""
|
||||
|
||||
@@ -250,3 +250,28 @@ class TestHasGroup(TransactionCase):
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
user_b.write({"groups_id": [Command.link(group_C.id)]})
|
||||
|
||||
def test_has_group_cleared_cache_on_write(self):
|
||||
self.registry._clear_cache()
|
||||
self.assertFalse(self.registry._Registry__cache, "Ensure ormcache is empty")
|
||||
|
||||
def populate_cache():
|
||||
self.test_user.has_group('test_user_has_group.group0')
|
||||
self.assertTrue(self.registry._Registry__cache, "user.has_group cache must be populated")
|
||||
|
||||
populate_cache()
|
||||
|
||||
self.env.ref(self.group0).write({"share": True})
|
||||
self.assertFalse(self.registry._Registry__cache, "Writing on group must invalidate user.has_group cache")
|
||||
|
||||
populate_cache()
|
||||
# call_cache_clearing_methods is called in res.groups.write to invalidate
|
||||
# cache before calling its parent class method (`odoo.models.Model.write`)
|
||||
# as explain in the `res.group.write` comment.
|
||||
# This verifies that calling `call_cache_clearing_methods()` invalidates
|
||||
# the ormcache of method `user.has_group()`
|
||||
self.env['ir.model.access'].call_cache_clearing_methods()
|
||||
self.assertFalse(
|
||||
self.registry._Registry__cache,
|
||||
"call_cache_clearing_methods() must invalidate user.has_group cache"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user