diff options
| author | Raphael Collet <rco@odoo.com> | 2020-11-16 11:50:19 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-11-17 09:11:57 +0000 |
| commit | cfb942ab5902e0992434eb2c7db2940526df404e (patch) | |
| tree | 3041b27338eebddccb8a5f1f0b957d6bcbd0824c /odoo/fields.py | |
| parent | a32bdf257d7a960fcd96cf6d32443bfe0295a296 (diff) | |
[FIX] core: avoid access error when flushing
This patch guarantees that computed fields with `compute_sudo=True` do
not cause access errors when fetched from database.
This fixes a non-deterministic access error upon `commit`, where fields
are recomputed and flushed with some random environment. The method
`recompute` performs its duty by accessing the fields to recompute. The
compute method of a field is called but does not assign it. As the
field is not in cache, its value is read from database. However, as the
latter is not done in superuser mode, it may cause some access error.
closes odoo/odoo#61820
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index 04dddd4013c..1aec507f21a 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -929,6 +929,7 @@ class Field(MetaField('DummyField', (object,), {})): # only a single record may be accessed record.ensure_one() + recomputed = False if self.compute and (record.id in env.all.tocompute.get(self, ())) \ and not env.is_protected(self, record): # self must be computed on record @@ -941,6 +942,7 @@ class Field(MetaField('DummyField', (object,), {})): self.compute_value(recs) except (AccessError, MissingError): self.compute_value(record) + recomputed = True try: value = env.cache.get(record, self) @@ -949,6 +951,8 @@ class Field(MetaField('DummyField', (object,), {})): if self.store and record.id: # real record: fetch from database recs = record._in_cache_without(self) + if recomputed and self.compute_sudo: + recs = recs.sudo() try: recs._fetch_field(self) except AccessError: |
