Skip to content

Fix FunctionMetadata.fields() crash when arg_names is None - #1638

Open
Tatamis wants to merge 1 commit into
dbcli:mainfrom
Tatamis:fix/function-metadata-fields-none-arg-names
Open

Tatamis wants to merge 1 commit into
dbcli:mainfrom
Tatamis:fix/function-metadata-fields-none-arg-names

Conversation

@Tatamis

@Tatamis Tatamis commented Sep 17, 2026

Copy link
Copy Markdown

Fixes #1204.

Bug

Autocompleting a call to a table-returning or variadic function whose parameters have no names (e.g. an unnamed variadic text[] argument, as in the reported hstore/labels(variadic text[]) example) crashes the completion thread:

File ".../pgcli/pgcompleter.py", line 985, in populate_scoped_cols
    cols = func.fields()
File ".../pgcli/packages/parseutils/meta.py", line 168, in fields
    for name, typ, mode in zip(self.arg_names, self.arg_types, self.arg_modes)
Exception 'NoneType' object is not iterable

fields() only guards against a missing arg_modes (elif not self.arg_modes: ...), then zips arg_names/arg_types/arg_modes unconditionally. arg_modes being truthy doesn't guarantee arg_names is populated too — a function can have modes but no names, in which case arg_names stays None and the zip() raises before it ever gets to filter by mode.

Fix

Fall back to None placeholders for arg_names/arg_types the same way args() (a few lines up in the same class) already falls back for arg_modes, so the zip always gets iterables.

Test plan

  • Added test_function_metadata_fields_with_variadic_and_no_arg_names, directly reproducing the reported case via FunctionMetadata.
  • Added test_function_metadata_fields_table_mode_with_no_arg_names, checking a TABLE-mode function with unnamed columns returns sensible ColumnMetadata (not just an empty list).
  • Verified both fail with the exact reported TypeError against the unpatched code.
  • pytest tests/ --ignore=tests/features — 2575 passed, 1 pre-existing failure unrelated to this change (a Windows-only tempfile permission issue in an unrelated alias-map test), 1 xfailed, 1 xpassed.
  • ruff check / ruff format clean.

Fixes dbcli#1204. fields() guarded against a missing arg_modes, but zipped
arg_names/arg_types/arg_modes unconditionally otherwise. A function
with a truthy arg_modes but no arg_names (e.g. an unnamed variadic
parameter, as in the reported hstore/variadic example) hit
'NoneType' object is not iterable instead of being handled.

Fall back to None placeholders for arg_names/arg_types the same way
args() already falls back for arg_modes a few lines up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NoneType exception in get_completions()

1 participant