diff options
| author | Raphael Collet <rco@odoo.com> | 2017-05-03 11:43:05 +0200 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2017-05-03 15:41:05 +0200 |
| commit | b59318ec12a1ce4e59de6d7bcde7146545b6c044 (patch) | |
| tree | f1c23d20305c2dfae87e3f2ad27e6fa525c00f27 /odoo/addons/base/tests/test_ir_actions.py | |
| parent | 1458f1b3135d373dac0625c7d4bd4a7eea3eaf54 (diff) | |
[REF] registry: always perform registry/cache signaling at the end of request
Problem: the update of custom models/fields is not fully transactional, and may
potentially lead to an inconsistent database. An other problem is creating two
custom fields by writing on a model: if the second one fails, the first one has
been committed without notice. Retrying the request will give an unexpected
error (duplicate field name).
Solution: never commit in the middle of a request. If the changes have an
impact on the registry, then mark it as invalid (with a new flag), and signal
registry invalidation after everything has been committed. If the request
fails, reset the registry. Both registry and cache invalidation are handled
the same way.
Diffstat (limited to 'odoo/addons/base/tests/test_ir_actions.py')
| -rw-r--r-- | odoo/addons/base/tests/test_ir_actions.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/odoo/addons/base/tests/test_ir_actions.py b/odoo/addons/base/tests/test_ir_actions.py index 344829c8181..4e0ee08d408 100644 --- a/odoo/addons/base/tests/test_ir_actions.py +++ b/odoo/addons/base/tests/test_ir_actions.py @@ -188,22 +188,19 @@ class TestCustomFields(common.TransactionCase): MODEL = 'res.partner' def setUp(self): - # use a test cursor instead of a real cursor + # check that the registry is properly reset registry = odoo.registry() - registry.enter_test_mode() fnames = set(registry[self.MODEL]._fields) - @self.addCleanup - def callback(): - registry.leave_test_mode() - # the tests may have modified the registry, reset it - with registry.cursor() as cr: - registry.clear_caches() - registry.setup_models(cr) - assert set(registry[self.MODEL]._fields) == fnames + def check_registry(): + assert set(registry[self.MODEL]._fields) == fnames super(TestCustomFields, self).setUp() + # use a test cursor instead of a real cursor + self.registry.enter_test_mode() + self.addCleanup(self.registry.leave_test_mode) + # do not reload the registry after removing a field self.env = self.env(context={'_force_unlink': True}) |
