From ce8d651cce61c79567e16c5a49a05d64abc8ed6d Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Thu, 4 Apr 2019 10:37:29 +0000 Subject: [PATCH] [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) --- odoo/fields.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/fields.py b/odoo/fields.py index f8b88fd1d90..954d33ee683 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -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)