Skip to content

Fix NoneType crash in FunctionMetadata.fields() for unnamed function args - #1659

Open
ParamTanna wants to merge 1 commit into
dbcli:mainfrom
ParamTanna:fix/function-fields-none
Open

ParamTanna wants to merge 1 commit into
dbcli:mainfrom
ParamTanna:fix/function-fields-none

Conversation

@ParamTanna

Copy link
Copy Markdown

Closes #1204.

FunctionMetadata.fields() crashes with TypeError: 'NoneType' object is not iterable while building column completions for certain functions. The reporter hit it on a variadic function, and a PostgreSQL argument can arrive with no name, so arg_names (and/or arg_types) is None while arg_modes is set. The zip(self.arg_names, self.arg_types, self.arg_modes) at the bottom of fields() then fails.

args(), right above fields(), already guards this with if not self.arg_names: return []. fields() only guarded arg_modes, so it missed the case. This extends the existing early-return condition to also cover arg_names/arg_types being falsy, falling back to the function-name output column, which is what the no-output-parameters branch already does.

Reproducer without a database:

from pgcli.packages.parseutils.meta import FunctionMetadata
FunctionMetadata("public", "labels", None, ["text[]"], ["v"], "hstore", False, False, False, False, None).fields()
# before: TypeError: 'NoneType' object is not iterable
# after:  [ColumnMetadata(name='labels', datatype='hstore', ...)]

Added a regression test in tests/parseutils/test_function_metadata.py, and the existing parseutils tests still pass. Happy to add a changelog entry if you would like one.

…li#1204)

fields() guarded only arg_modes, but a function argument can arrive with
no name (an unnamed variadic arg), so arg_names is None while arg_modes is
set, and the zip() raised NoneType is not iterable during completion.
args() right above already guards arg_names; fields() now guards it too,
falling back to the function-name output column as the no-output-parameters
branch does.

This branch has not been deployed

No deployments
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