summaryrefslogtreecommitdiff
path: root/odoo/addons/base
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/base
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/base')
-rw-r--r--odoo/addons/base/models/ir_model.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py
index adbae99303a..a2dbffe57b1 100644
--- a/odoo/addons/base/models/ir_model.py
+++ b/odoo/addons/base/models/ir_model.py
@@ -1379,8 +1379,15 @@ class IrModelSelection(models.Model):
if not field or not field.store or Model._abstract:
continue
- ondelete = (field.ondelete or {}).get(selection.value) or 'set null'
- if callable(ondelete):
+ ondelete = (field.ondelete or {}).get(selection.value)
+ # special case for custom fields
+ if ondelete is None and field.manual and not field.required:
+ ondelete = 'set null'
+
+ if ondelete is None:
+ # nothing to do, the selection does not come from a field extension
+ continue
+ elif callable(ondelete):
ondelete(selection._get_records())
elif ondelete == 'set null':
selection._get_records().write({field.name: False})