diff options
| author | Adrian Torres <adt@odoo.com> | 2020-02-13 16:31:17 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-03-30 13:42:04 +0000 |
| commit | f0481392c6501cae2c38359f526da1eefa451337 (patch) | |
| tree | e17b0fedb9abeb7ee71380005c1e7f8ec4ca9891 /odoo/addons/test_new_api/tests/test_schema.py | |
| parent | 96223568c445bc1d378fa4d8833f90d3dad8ec7e (diff) | |
[IMP] core: introduce mechanism for selection_add cleanup
- Let A and B be two different modules.
- A defines a required Selection field F of model M and B extends
it through the `selection_add` argument.
- Create records of model M and have some of them have any of the
options introduced by module B selected for field F.
- Uninstall module B.
The result will be records of Model M with an option for field F that no
longer exists, this makes the registry inconsistent and prone to
crashing (it is sufficient to access the form view of such a record to
trigger a crash).
This commit introduces a mechanism similar to the `ondelete` argument
found in Many2one fields, the argument name is the same but it's
different both in behaviour and in implementation.
The `ondelete` mechanism for Selection fields is enforced for **any**
Selection field with required set to `True`, this means that the
developer is required to set a cleanup behaviour for when their module
is uninstalled. For possible cleanup options, see fields.Selection's
docstring.
As far as implementation goes, everything is implemented in Python
unlike with Many2one fields where the behaviour is delegated to
PostgreSQL.
The `ondelete` setting will be processed during
`ir.model.fields.selection.unlink()` to ensure that the registry is left
in an appropriate state after module uninstall.
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_schema.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_schema.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/odoo/addons/test_new_api/tests/test_schema.py b/odoo/addons/test_new_api/tests/test_schema.py index 4aa99e87a47..d8849dd22f6 100644 --- a/odoo/addons/test_new_api/tests/test_schema.py +++ b/odoo/addons/test_new_api/tests/test_schema.py @@ -3,13 +3,24 @@ from odoo.models import MetaModel from odoo.tests import common +def get_model_name(cls): + name = cls._name + if not name: + [name] = cls._inherit if isinstance(cls._inherit, list) else [cls._inherit] + assert isinstance(name, str) + return name + + class TestReflection(common.TransactionCase): """ Test the reflection into 'ir.model', 'ir.model.fields', etc. """ def test_models_fields(self): """ check that all models and fields are reflected as expected. """ # retrieve the models defined in this module, and check them - model_names = {cls._name for cls in MetaModel.module_to_models['test_new_api']} + model_names = { + get_model_name(cls) + for cls in MetaModel.module_to_models['test_new_api'] + } ir_models = self.env['ir.model'].search([('model', 'in', list(model_names))]) self.assertEqual(len(ir_models), len(model_names)) for ir_model in ir_models: |
