summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-04-02 06:45:54 +0000
committerRaphael Collet <rco@odoo.com>2020-04-03 11:40:29 +0000
commita233d534c2c4e9f1417c85ead92249a5d8c83b3a (patch)
tree219bb02663d7cd79985b3593f35c72106583b070
parent9afce4805fc8bac45fdba817488aa867fddff69b (diff)
[FIX] core: add NOT NULL constraints in post-init
The method `_init_column` for the field `alias_id` of `mail.alias.mixin` requires the reflection of models, because `mail.alias` records have a many2one field to `ir.model`. The actual initialization of the column is thus performed in post-init phase (after reflection). Therefore, the NOT NULL constraint cannot be added right away. X-original-commit: 2e3400f149ce4ed4c00bc49a519f58993b49bc51
-rw-r--r--odoo/fields.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index b96c9fe64f8..fc1a225ef34 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -823,11 +823,15 @@ class Field(MetaField('DummyField', (object,), {})):
# the column is new or it becomes required; initialize its values
if model._table_has_rows():
model._init_column(self.name)
+
+ if self.required and not has_notnull:
+ # _init_column may delay computations in post-init phase
+ @model.pool.post_init
+ def add_not_null():
# flush values before adding NOT NULL constraint
model.flush([self.name])
+ model.pool.post_constraint(sql.set_not_null, model._cr, model._table, self.name)
- if self.required and not has_notnull:
- model.pool.post_constraint(sql.set_not_null, model._cr, model._table, self.name)
elif not self.required and has_notnull:
sql.drop_not_null(model._cr, model._table, self.name)