From 0bec85dcabb548b5ccc5e177cf481ecafc53e700 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 14 Sep 2022 14:30:39 +0000 Subject: [PATCH] [FIX] core: remove confused log message about existing index When a module extends model 'base', the database schemas of all models are checked, including indexes. And a log message appears for "unexpected index mail_message_subtype_id_index on table mail_message_subtype". The index indeed exists, but not for the table mentioned in the message. The ORM actually makes a confusion between: - the index mail_message_subtype_id_index for subtype_id on table mail_message - the index mail_message_subtype_id_index for id on table mail_message_subtype The fix consists in logging the message about the unexpected index only if the index is on the expected table. closes odoo/odoo#100297 X-original-commit: fe8d0024897208e876f097564d50e6795df2c1d3 Signed-off-by: Raphael Collet --- odoo/modules/registry.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index 5862ccaac0d..d286c3c0494 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -466,9 +466,10 @@ class Registry(Mapping): if not expected: return - cr.execute("SELECT indexname FROM pg_indexes WHERE indexname IN %s", + # retrieve existing indexes with their corresponding table + cr.execute("SELECT indexname, tablename FROM pg_indexes WHERE indexname IN %s", [tuple(row[0] for row in expected)]) - existing = {row[0] for row in cr.fetchall()} + existing = dict(cr.fetchall()) for indexname, tablename, field, unaccent in expected: column_expression = f'"{field.name}"' @@ -503,7 +504,8 @@ class Registry(Mapping): sql.create_index(cr, indexname, tablename, [expression], method, where) except psycopg2.OperationalError: _schema.error("Unable to add index for %s", self) - elif not index and indexname in existing: + + elif not index and tablename == existing.get(indexname): _schema.info("Keep unexpected index %s on table %s", indexname, tablename) def add_foreign_key(self, table1, column1, table2, column2, ondelete,