diff options
| author | Raphael Collet <rco@odoo.com> | 2020-10-26 15:35:40 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-10-27 12:42:39 +0000 |
| commit | 67152bf82da2674179297d32e4cec9dd534fa0c9 (patch) | |
| tree | a13d31ebb9083e9245636d3c0e431b8ae93db07e /odoo/modules/loading.py | |
| parent | 7342cadcfe8d85edb8a53aef0ecc402dbbc7e935 (diff) | |
[FIX] core: reinstall hooks after setting up models in registry
Before this patch, adding a field on a custom model discards all
automated actions on that model. The explanation is relatively simple.
When models are set up in the registry, the classes of custom models are
dropped then recreated. Given that automated actions are implemented as
monkey-patches on model classes, the setup of models simply loses those
monkey-patches, which explains why they stop working on custom models.
The fix introduces an `_unregister_hook()` method, that is expected to
clean up what has been done in `_register_hook()`. When the registry is
ready (i.e., not being loaded), the setup of models first invokes
`_unregister_hook()` on models, proceeds with the setup, and finally
invokes `_register_hook()` to reinstall the hooks.
OPW 2362308
closes odoo/odoo#60818
X-original-commit: ac970380deaafb8542670951ed63dc11ffaf6b6c
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/modules/loading.py')
| -rw-r--r-- | odoo/modules/loading.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py index 515cd4763bb..50cbffa83ed 100644 --- a/odoo/modules/loading.py +++ b/odoo/modules/loading.py @@ -556,6 +556,10 @@ def load_modules(db, force_demo=False, status=None, update_module=False): _logger.error('At least one test failed when loading the modules.') # STEP 8: call _register_hook on every model + # This is done *exactly once* when the registry is being loaded. See the + # management of those hooks in `Registry.setup_models`: all the calls to + # setup_models() done here do not mess up with hooks, as registry.ready + # is False. env = api.Environment(cr, SUPERUSER_ID, {}) for model in env.values(): model._register_hook() |
