diff options
| author | Adrian Torres <adt@odoo.com> | 2019-10-11 07:19:43 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-10-15 14:33:07 +0000 |
| commit | 73b18b30b5fcad43a08407d4cfa13b6c55c58f4c (patch) | |
| tree | 5862d2fe1bdad4a07a497cdbb8738fe08ba7b36f /odoo/addons/test_new_api/tests/test_new_fields.py | |
| parent | b2a403efc7796d77b42162483e6f1030de96153f (diff) | |
[FIX] base: don't crash during CRUD if record does not exist
- Let a model M define a Many2oneReference field F1.
- Let a model N define a One2many field F2 whose inverse is M->F1
- Define a computed field N->F3 that depends on N->F2
If, for whatever reason, a recordset of M contains records that have
been unlinked already and we try to unlink them again, the system will
crash with a MissingException error.
This happened because, while most _modified_trigger cases cover the case
of a MissingException (i.e. record not in cache), the case for a
Many2oneReference didn't.
This is fixed by simply ignoring these "stale" records in the
_modified_triggers section for Many2oneReference fields.
closes odoo/odoo#38816
X-original-commit: f3b05032f0576befda4dca870718afd429c21b0f
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Co-authored-by: mreficent <miquel.raich@eficent.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py')
| -rw-r--r-- | odoo/addons/test_new_api/tests/test_new_fields.py | 12 |
1 files changed, 12 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 7d968aac0fe..e326d8575b1 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -2001,3 +2001,15 @@ class TestRequiredMany2oneTransient(common.TransactionCase): with self.assertRaises(ValueError): field._setup_regular_base(Model) + + +@common.tagged('m2oref') +class TestMany2oneReference(common.TransactionCase): + + def test_delete_m2o_reference_records(self): + m = self.env['test_new_api.model_many2one_reference'] + self.env.cr.execute("SELECT max(id) FROM test_new_api_model_many2one_reference") + ids = self.env.cr.fetchone() + # fake record to emulate the unlink of a non-existant record + foo = m.browse(1 if not ids[0] else (ids[0] + 1)) + self.assertTrue(foo.unlink()) |
