From dbf389fb28f13fca495c1a818e4da966745c13e8 Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Thu, 3 Sep 2026 13:03:04 +0530 Subject: [PATCH] refactor: do not fail Rust deserialization when search_path is empty When search_path was empty the context returned a null value, which Rust failed to parse as a Vec. Now we return an empty array if search_path is empty. --- sql/load_sql_context.sql | 7 ++++++- test/expected/issue_650.out | 24 ++++++++++++++++++++++++ test/sql/issue_650.sql | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/expected/issue_650.out create mode 100644 test/sql/issue_650.sql diff --git a/sql/load_sql_context.sql b/sql/load_sql_context.sql index d8a460e1..fc91f4c4 100644 --- a/sql/load_sql_context.sql +++ b/sql/load_sql_context.sql @@ -34,7 +34,12 @@ schemas_(oid, name) as ( select jsonb_build_object( 'config', jsonb_build_object( - 'search_path', (select array_agg(schema_oid) from search_path_oids), + -- array_agg returns null when the search path is empty. Coalesce so + -- the context still deserializes into a (empty) sequence. Issue #650 + 'search_path', coalesce( + (select array_agg(schema_oid) from search_path_oids), + '{}'::oid[] + ), 'role', current_role, 'schema_version', graphql.get_schema_version() ), diff --git a/test/expected/issue_650.out b/test/expected/issue_650.out new file mode 100644 index 00000000..78f4e328 --- /dev/null +++ b/test/expected/issue_650.out @@ -0,0 +1,24 @@ +begin; + create table test_table ( + id serial primary key, + name text not null, + description text + ); + comment on schema public is e'@graphql({"introspection": true})'; + -- baseline: a non-empty search_path resolves fine + set local search_path to public; + select graphql.resolve('{ __typename }'); + resolve +----------------------------------- + {"data": {"__typename": "Query"}} +(1 row) + + -- an empty search_path should also resolve, with no visible schemas + set local search_path to ''; + select graphql.resolve('{ __typename }'); + resolve +----------------------------------- + {"data": {"__typename": "Query"}} +(1 row) + +rollback; diff --git a/test/sql/issue_650.sql b/test/sql/issue_650.sql new file mode 100644 index 00000000..ea78901e --- /dev/null +++ b/test/sql/issue_650.sql @@ -0,0 +1,19 @@ +begin; + + create table test_table ( + id serial primary key, + name text not null, + description text + ); + + comment on schema public is e'@graphql({"introspection": true})'; + + -- baseline: a non-empty search_path resolves fine + set local search_path to public; + select graphql.resolve('{ __typename }'); + + -- an empty search_path should also resolve, with no visible schemas + set local search_path to ''; + select graphql.resolve('{ __typename }'); + +rollback;