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/addons/test_new_api | |
| 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/addons/test_new_api')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index c07a299cfe6..fe68fdac776 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -646,6 +646,29 @@ class TestFields(TransactionCaseWithUserDemo): self.assertEqual(record.bars, False) self.assertEqual(record.bares, False) + def test_16_compute_unassigned_access_error(self): + # create a real record + record = self.env['test_new_api.compute.unassigned'].create({}) + record.flush() + + # alter access rights: regular users cannot read 'record' + access = self.env.ref('test_new_api.access_test_new_api_compute_unassigned') + access.perm_read = False + + # switch to environment with user demo + record = record.with_user(self.user_demo) + record.env.cache.invalidate() + + # check that the record is not accessible + with self.assertRaises(AccessError): + record.bars + + # modify the record and flush() changes with the current environment: + # this should not trigger an access error, even if unassigned computed + # fields are fetched from database + record.foo = "X" + record.flush() + def test_20_float(self): """ test rounding of float fields """ record = self.env['test_new_api.mixed'].create({}) |
