Skip to content

completion_refresh thread crashes with KeyError #1590

@shgol

Description

@shgol

Description

I get the following Exception a few seconds after connecting to the db

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.14/3.14.4_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/threading.py", line 1082, in _bootstrap_inner
    self._context.run(self.run)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.14/3.14.4_1/Frameworks/Python.framework/Versions/3.14/lib/python3.14/threading.py", line 1024, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pgcli/4.4.0_1/libexec/lib/python3.14/site-packages/pgcli/completion_refresher.py", line 63, in _bg_refresh
    refresher(completer, executor)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pgcli/4.4.0_1/libexec/lib/python3.14/site-packages/pgcli/completion_refresher.py", line 111, in refresh_tables
    completer.extend_columns(executor.table_columns(), kind="tables")
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pgcli/4.4.0_1/libexec/lib/python3.14/site-packages/pgcli/pgcompleter.py", line 232, in extend_columns
    metadata[schema][relname][colname] = column
    ~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'some_table_name'

You can reproduce this by creating a table in between the calls to extend_relations and extend_columns in completion_refresher.py. The dict keyed on relname doesn't get created, and then after the table is created extend_columns looks up the new table and gets KeyError.
I repro this consistently due to another process programmatically creating tables often.

repro'd on pgcli 4.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions