summaryrefslogtreecommitdiff
path: root/odoo/models.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2021-01-08 09:55:30 +0000
committerRaphael Collet <rco@odoo.com>2021-01-08 10:50:26 +0000
commitb7676ec33172e6196b5fd1eda4df730ebf90eb6b (patch)
treecbb9d1b3f5fb233e794167f70eda75d4f618daa4 /odoo/models.py
parent4fcacfac8967a3facbe751f748faff02033ce0ae (diff)
[FIX] core: avoid access error when flushing
This takes a former patch one step further. Assume you recompute a field on two records, and the computation assigns the first record but not the second one. Before this patch, the recomputation process was accessing the field on both records. When accessing the first record, both records are recomputed, and the value of the first one is found in cache. When accessing the second record, no recomputation is made (it has been done already), and the cache is empty. The field is thus fetched from database, and this crashes because of insufficient access rights. This scenario was causing some obscure nondeterministic crashes in tests. The nondeterminism comes from the choice of the environment for flushing (it should not be in superuser mode); the order of records in the set to compute; the order in which records are assigned in the compute method; the fact that the compute method should assign some records and some not. The fix consists in adding a method that processes pending computations, without doing anything special for unassigned records. The method is used in field accessors (__get__ and mapped) and in method recompute(). The access error is gone because the recomputation no longer tries to get the value of a field to compute. closes odoo/odoo#64250 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/models.py')
-rw-r--r--odoo/models.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/odoo/models.py b/odoo/models.py
index ae7b6f2f995..be36edcdc79 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -5869,10 +5869,10 @@ Fields:
# recomputed by accessing the field on the records
recs = recs.filtered('id')
try:
- recs.mapped(field.name)
+ field.recompute(recs)
except MissingError:
existing = recs.exists()
- existing.mapped(field.name)
+ field.recompute(existing)
# mark the field as computed on missing records, otherwise
# they remain forever in the todo list, and lead to an
# infinite loop...