fix: hasSingleUnnamedParam incorrectly matching named parameters

The hasSingleUnnamedParam function was only checking the parameter type
but not whether the parameter actually had no name. This caused functions
with a single NAMED parameter (e.g., `foo(data json)`) to incorrectly
match the single-param fallback mode.

The result was a confusing PostgreSQL error 42883 "function does not exist"
instead of a clean PGRST202 error explaining that no matching function
was found.

Added ppName == mempty check so functions with named parameters don't
incorrectly match the single-param fallback.
This commit is contained in:
Joel Jakobsson
2025-12-15 15:34:48 -05:00
committed by GitHub
parent 60c70c5b37
commit fd6a3bdccf
4 changed files with 30 additions and 9 deletions
+13 -1
View File
@@ -1146,12 +1146,24 @@ spec =
}
context "single unnamed param" $ do
it "can insert json directly" $
it "can insert json directly with unnamed parameter" $
post "/rpc/unnamed_json_param"
[json|{"A": 1, "B": 2, "C": 3}|]
`shouldRespondWith`
[json|{"A": 1, "B": 2, "C": 3}|]
it "rejects json body when single param has a name" $
post "/rpc/named_json_param"
[json|{"A": 1, "B": 2, "C": 3}|]
`shouldRespondWith`
[json|{
"code":"PGRST202",
"message":"Could not find the function test.named_json_param(A, B, C) in the schema cache",
"details":"Searched for the function test.named_json_param with parameters A, B, C or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.",
"hint":null
}|]
{ matchStatus = 404 }
it "can insert text directly" $ do
request methodPost "/rpc/unnamed_text_param"
[("Content-Type", "text/plain"), ("Accept", "text/plain")]
+5
View File
@@ -2356,6 +2356,11 @@ create or replace function test.unnamed_json_param(json) returns json as $$
select $1;
$$ language sql;
-- Function with a NAMED json parameter (for testing single param fallback behavior)
create or replace function test.named_json_param(data json) returns json as $$
select data;
$$ language sql;
create or replace function test.unnamed_text_param(text) returns "text/plain" as $$
select $1::"text/plain";
$$ language sql;