[FIX] core: invalidate the cache of forbidden records when raising AccessError

Issue: checking access rules fetches some data in cache.  Sometimes,
accessing a forbidden record does not crash because of the data left in
cache.  This is the case when accessing a field on a record, like in the
field accessor method:

    try:
        records._fetch_field(f)     # (1)
    except AccessError:
        record._fetch_field(f)      # (2)

The field f is included in the data fetched to check access rules in the
prefetch set of record (1).  Therefore, when trying to fetch the same
field in (2), there is nothing to fetch and no access error occurs.

Part-of: odoo/odoo#112126
This commit is contained in:
Raphael Collet
2023-03-05 15:12:55 +01:00
parent e962860c6f
commit 4e6f1d7805
2 changed files with 3 additions and 0 deletions
+1
View File
@@ -203,6 +203,7 @@ class IrRule(models.Model):
resolution_info = _("Contact your administrator to request access if necessary.")
if not self.env.user.has_group('base.group_no_one') or not self.env.user.has_group('base.group_user'):
records.invalidate_recordset()
return AccessError(f"{operation_error}\n\n{resolution_info}")
# This extended AccessError is only displayed in debug mode.
+2
View File
@@ -1161,6 +1161,8 @@ class Field(MetaField('DummyField', (object,), {})):
try:
recs._fetch_field(self)
except AccessError:
if len(recs) == 1:
raise
record._fetch_field(self)
if not env.cache.contains(record, self):
raise MissingError("\n".join([