Skip to content

Fix NoneType crash completing functions with unnamed args#1605

Open
youdie006 wants to merge 1 commit into
dbcli:mainfrom
youdie006:fix/function-metadata-none-guard
Open

Fix NoneType crash completing functions with unnamed args#1605
youdie006 wants to merge 1 commit into
dbcli:mainfrom
youdie006:fix/function-metadata-none-guard

Conversation

@youdie006

Copy link
Copy Markdown

Description

FunctionMetadata.fields() (pgcli/packages/parseutils/meta.py) called zip(self.arg_names, self.arg_types, self.arg_modes). For a function with unnamed (variadic) arguments — e.g. the hstore example labels(variadic text[])arg_names is normalized to None while arg_modes stays truthy, so zip(None, ...) raised 'NoneType' object is not iterable and crashed get_completions() (#1204).

The fix guards the zip with or [] (the same guard args() already uses):

for name, typ, mode in zip(self.arg_names or [], self.arg_types or [], self.arg_modes)

Added a regression test in tests/parseutils/test_function_metadata.py reproducing the variadic / no-arg-names case (red before the fix, green after). Full completion + parseutils sweep: 2450 passed; ruff clean.

Closes #1204

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (pytest: regression test passes; full completion/parseutils sweep 2450 passed; ruff clean).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

FunctionMetadata.fields() called zip() over self.arg_names, which is None for
functions with unnamed (variadic) arguments such as hstore's
labels(variadic text[]), raising "'NoneType' object is not iterable" in
get_completions(). Guard the zip with 'or []' (mirroring args()). Adds a
regression test plus changelog and AUTHORS entries.

Closes dbcli#1204

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0a6009909

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return [
ColumnMetadata(name, typ, [])
for name, typ, mode in zip(self.arg_names, self.arg_types, self.arg_modes)
for name, typ, mode in zip(self.arg_names or [], self.arg_types or [], self.arg_modes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return the scalar field for variadic-only functions

When proargmodes is populated only because the function has input/variadic parameters, this now zips an empty arg_names list and returns []. That avoids the crash, but it also means populate_scoped_cols() gets no column metadata for functions such as labels(variadic text[]) RETURNS hstore, even though the existing comment above says functions without output parameters should expose the function name as the output column. In completions for FROM labels(...) l, this silently drops the labels column instead of falling back to ColumnMetadata(self.func_name, self.return_type, []) when no OUT/INOUT/TABLE modes are present.

Useful? React with 👍 / 👎.

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