From c0a600990986a9da9416fd9c801134ea5e634470 Mon Sep 17 00:00:00 2001 From: youdie006 Date: Sat, 20 Jun 2026 22:40:28 +0900 Subject: [PATCH] Fix NoneType crash completing functions with unnamed arguments 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 #1204 --- AUTHORS | 1 + changelog.rst | 8 ++++++++ pgcli/packages/parseutils/meta.py | 2 +- tests/parseutils/test_function_metadata.py | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index aef249cef..d3f73aab7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -148,6 +148,7 @@ Contributors: * Charalampos Stratakis * Laszlo Bimba (bimlas) * Anjanna + * youdie006 Creator: -------- diff --git a/changelog.rst b/changelog.rst index 4d2f529b2..ded3dccd7 100644 --- a/changelog.rst +++ b/changelog.rst @@ -1,3 +1,11 @@ +4.5.1 (unreleased) +================== + +Bug fixes: +---------- +* Fix ``NoneType`` crash when completing functions with unnamed (variadic) arguments (#1204). + + 4.5.0 (2026-06-02) ================== diff --git a/pgcli/packages/parseutils/meta.py b/pgcli/packages/parseutils/meta.py index df41cf4ee..ca96fd8ea 100644 --- a/pgcli/packages/parseutils/meta.py +++ b/pgcli/packages/parseutils/meta.py @@ -159,6 +159,6 @@ def fields(self): 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) if mode in ("o", "b", "t") ] # OUT, INOUT, TABLE diff --git a/tests/parseutils/test_function_metadata.py b/tests/parseutils/test_function_metadata.py index c4000ab1c..05fd4bf5e 100644 --- a/tests/parseutils/test_function_metadata.py +++ b/tests/parseutils/test_function_metadata.py @@ -11,3 +11,25 @@ def test_function_metadata_eq(): assert not (f1 == f3) assert hash(f1) == hash(f2) assert hash(f1) != hash(f3) + + +def test_function_metadata_fields_with_variadic_and_no_arg_names(): + # Regression for issue #1204: a function with a VARIADIC argument that has + # a type but no name (e.g. `labels(variadic text[]) RETURNS hstore`) leaves + # arg_names as None while arg_modes is truthy. fields() must not raise + # "'NoneType' object is not iterable". + f = FunctionMetadata( + "public", + "labels", + None, # arg_names: variadic arg has no name + ["text[]"], + ["v"], # VARIADIC + "hstore", + False, + False, + False, + False, + None, + ) + # No OUT/INOUT/TABLE columns, so fields() yields nothing. + assert f.fields() == []