From 5b1beec1f2840f3558b279b5726b0afa722128db Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 20 Jun 2016 11:53:59 +0200 Subject: [PATCH] [FIX] models: commit *before* trying to set NOT NULL constraint Setting NOT NULL constraints on required fields may fail if there are any row with unset value for this column. The ORM handle this case by catching the exception raised and warning user. However, not commiting the current transaction before, will rollback changes made before like setting default values or renaming a column. --- openerp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/models.py b/openerp/models.py index f2441ef9ca3..7d4f6e5220a 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -2585,8 +2585,8 @@ class BaseModel(object): self._set_default_value_on_column(cr, k, context=context) # add the NOT NULL constraint try: - cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False) cr.commit() + cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" SET NOT NULL' % (self._table, k), log_exceptions=False) _schema.debug("Table '%s': column '%s': added NOT NULL constraint", self._table, k) except Exception: