[FIX] orm: don't crash on index creation

Creating field indexes might not always be possible.  For instance,
adding an index on an existing Char/Text field will fail if the column
contains values longer than 8192 bytes (PostgreSQL limit for BTrees).

Instead of failing miserably during the schema modification, simply log
the problem and continue.

closes odoo/odoo#32416

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Damien Bouvy
2019-04-04 11:47:20 +00:00
committed by Raphael Collet
parent 8b6be83f70
commit ce8d651cce
+5 -1
View File
@@ -901,7 +901,11 @@ class Field(MetaField('DummyField', (object,), {})):
"""
indexname = '%s_%s_index' % (model._table, self.name)
if self.index:
sql.create_index(model._cr, indexname, model._table, ['"%s"' % self.name])
try:
with model._cr.savepoint():
sql.create_index(model._cr, indexname, model._table, ['"%s"' % self.name])
except psycopg2.OperationalError:
_schema.error("Unable to add index for %s", self)
else:
sql.drop_index(model._cr, indexname, model._table)