summaryrefslogtreecommitdiff
path: root/odoo/addons/test_new_api/tests/test_new_fields.py
diff options
context:
space:
mode:
authorAdrian Torres <adt@odoo.com>2021-03-04 13:27:37 +0000
committerAdrian Torres <adt@odoo.com>2021-03-10 13:12:15 +0000
commit2e238f1e0202d65a98177939dac166dd659bb39c (patch)
treee918e5a40d5e52c80d4b9d1ca0bb0c8ed57e4480 /odoo/addons/test_new_api/tests/test_new_fields.py
parente66ef561d9b75eca307a1702fac4f8e4ada6237f (diff)
[FIX] base: do not assign default ondelete policy for base fields
Previously, an ondelete policy would be assigned to any required Selection fields, the default policy being 'set null'. Base fields do **not** require an ondelete value, since if they are deleted there is no "data fix" to apply because the field's column is dropped, and in fact it's error-prone to do so because during `_process_ondelete`, the system would attempt to set to null fields that were required (i.e. NOT NULL). This issue is hidden by the fact that ir.model.fields are usually deleted **before** ir.model.fields.selection and thus the ondelete action won't be applied on the field with the original definition (because it has probably been deleted by SQL CASCADE)
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.py10
1 files changed, 10 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 61de1807c2c..ed3478af1dd 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -3053,6 +3053,16 @@ class TestSelectionOndelete(common.TransactionCase):
self.assertFalse(rec.my_selection)
+ def test_required_base_selection_field(self):
+ # test that no ondelete action is executed on a required selection field that is not
+ # extended, only required fields that extend it with selection_add should
+ # have ondelete actions defined
+ rec = self.env[self.MODEL_REQUIRED].create({'my_selection': 'foo'})
+ self.assertEqual(rec.my_selection, 'foo')
+
+ self._unlink_option(self.MODEL_REQUIRED, 'foo')
+ self.assertEqual(rec.my_selection, 'foo')
+
@common.tagged('selection_ondelete_advanced')
class TestSelectionOndeleteAdvanced(common.TransactionCase):