summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorDamien Bouvy <dbo@odoo.com>2019-04-04 10:37:29 +0000
committerRaphael Collet <rco@odoo.com>2019-04-04 11:47:20 +0000
commitce8d651cce61c79567e16c5a49a05d64abc8ed6d (patch)
treea44afc203074d9992a5656e1d8c6cafcb3f033ad /odoo/fields.py
parent8b6be83f70ea7b25dd7f66bd8889a5b92b3ec658 (diff)
[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>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py6
1 files changed, 5 insertions, 1 deletions
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)