diff --git a/mycli/completion_refresher.py b/mycli/completion_refresher.py index eb684b55..662dd331 100644 --- a/mycli/completion_refresher.py +++ b/mycli/completion_refresher.py @@ -114,8 +114,9 @@ def refresh_schemata(completer, executor): @refresher("tables") def refresh_tables(completer, executor): - completer.extend_relations(executor.tables(), kind="tables") - completer.extend_columns(executor.table_columns(), kind="tables") + table_columns_dbresult = list(executor.table_columns()) + completer.extend_relations(table_columns_dbresult, kind="tables") + completer.extend_columns(table_columns_dbresult, kind="tables") @refresher("users") diff --git a/mycli/sqlcompleter.py b/mycli/sqlcompleter.py index 44344cbd..16362899 100644 --- a/mycli/sqlcompleter.py +++ b/mycli/sqlcompleter.py @@ -1010,6 +1010,13 @@ def extend_columns(self, column_data, kind): metadata = self.dbmetadata[kind] for relname, column in column_data: + if relname not in metadata[self.dbname]: + _logger.error("relname '%s' was not found in db '%s'", relname, self.dbname) + # this could happen back when the completer populated via two calls: + # SHOW TABLES then SELECT table_name, column_name from information_schema.columns + # it's a slight race, but much more likely on Vitess picking random shards for each. + # see discussion in https://github.com/dbcli/mycli/pull/1182 (tl;dr - let's keep it) + continue metadata[self.dbname][relname].append(column) self.all_completions.add(column)