Skip to content
Permalink
Browse files

[FIX] models: postpone sql constraints after module initialisation

Make sure SQL constraints can apply on compute store fields,
even for modules extensions.

SQL constraints can apply after module creation for new models, because
the new model table is empty (no row to invalidate the constraints).

But for extended models, we have to apply SQL constraints (and required)
after compute store computation, otherwise the constraint may not be applicable
to current records because the compute stored columns are empty (not already computed).
  • Loading branch information
Feyensv committed Jan 16, 2020
1 parent 9c9db94 commit 6c95ba09f50fa3547cdc99a26c828cabbb2881d2
Showing with 2 additions and 2 deletions.
  1. +2 −2 odoo/models.py
@@ -2521,8 +2521,8 @@ def mark_fields_to_compute():
# when the table already exists (IntegrityError)
field.update_db_notnull(self, columns.get(field.name))

if self._auto:
self._add_sql_constraints()
if self._auto:
self.pool.post_init(self._add_sql_constraints)

if must_create_table:
self._execute_sql()

0 comments on commit 6c95ba0

Please sign in to comment.
You can’t perform that action at this time.