Fix NoneType crash completing functions with unnamed args#1605
Fix NoneType crash completing functions with unnamed args#1605youdie006 wants to merge 1 commit into
Conversation
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
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
Description
FunctionMetadata.fields()(pgcli/packages/parseutils/meta.py) calledzip(self.arg_names, self.arg_types, self.arg_modes). For a function with unnamed (variadic) arguments — e.g. the hstore examplelabels(variadic text[])—arg_namesis normalized toNonewhilearg_modesstays truthy, sozip(None, ...)raised'NoneType' object is not iterableand crashedget_completions()(#1204).The fix guards the zip with
or [](the same guardargs()already uses):Added a regression test in
tests/parseutils/test_function_metadata.pyreproducing the variadic / no-arg-names case (red before the fix, green after). Full completion + parseutils sweep: 2450 passed;ruffclean.Closes #1204
Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).ruffclean).