diff options
| author | Adrian Torres <adt@odoo.com> | 2020-02-05 15:57:04 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-02-06 18:28:29 +0000 |
| commit | f61262eb08134ba5bdf9099445fe821769842bb3 (patch) | |
| tree | 43dc1421445c45786d085fa3787ed579655e5ac2 /odoo/tools/sql.py | |
| parent | f6a1437aeb0c9e243d823450018d97b7c10385c6 (diff) | |
[FIX] core: delay constraint application in case of upgrade
closes odoo/odoo#44800
Co-authored-with: Xavier Dollé <xdo@odoo.com>
X-original-commit: bc2bb5e03c2b32d4ee1b0597ea5889c17d2b0e0e
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Diffstat (limited to 'odoo/tools/sql.py')
| -rw-r--r-- | odoo/tools/sql.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py index 1c3fa9e98a4..3bcbd39e139 100644 --- a/odoo/tools/sql.py +++ b/odoo/tools/sql.py @@ -109,12 +109,10 @@ def set_not_null(cr, tablename, columnname): query = 'ALTER TABLE "{}" ALTER COLUMN "{}" SET NOT NULL'.format(tablename, columnname) try: with cr.savepoint(flush=False): - cr.execute(query) + cr.execute(query, log_exceptions=False) _schema.debug("Table %r: column %r: added constraint NOT NULL", tablename, columnname) except Exception: - msg = "Table %r: unable to set NOT NULL on column %r!\n" \ - "If you want to have it, you should update the records and execute manually:\n%s" - _schema.warning(msg, tablename, columnname, query, exc_info=True) + raise Exception("Table %r: unable to set NOT NULL on column %r", tablename, columnname) def drop_not_null(cr, tablename, columnname): """ Drop the NOT NULL constraint on the given column. """ @@ -138,13 +136,11 @@ def add_constraint(cr, tablename, constraintname, definition): query2 = 'COMMENT ON CONSTRAINT "{}" ON "{}" IS %s'.format(constraintname, tablename) try: with cr.savepoint(flush=False): - cr.execute(query1) - cr.execute(query2, (definition,)) + cr.execute(query1, log_exceptions=False) + cr.execute(query2, (definition,), log_exceptions=False) _schema.debug("Table %r: added constraint %r as %s", tablename, constraintname, definition) except Exception: - msg = "Table %r: unable to add constraint %r!\n" \ - "If you want to have it, you should update the records and execute manually:\n%s" - _schema.warning(msg, tablename, constraintname, query1, exc_info=True) + raise Exception("Table %r: unable to add constraint %r as %s", tablename, constraintname, definition) def drop_constraint(cr, tablename, constraintname): """ drop the given constraint. """ |
