From 41a4396147918948bd5283e878543f3683de81b5 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 5 Feb 2022 10:45:35 +0100 Subject: [PATCH] fix: Remove uncallable functions from schema cache and OpenAPI output Signed-off-by: Wolfgang Walther --- CHANGELOG.md | 1 + src/PostgREST/DbStructure.hs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71a6439e8..338e0ed30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez - #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther - #2101, Remove aggregates, procedures and window functions from the schema cache and OpenAPI output. - @wolfgangwalther + - #2152, Remove functions, which are uncallable because of unnamend arguments from schema cache and OpenAPI output. - @wolfgangwalther - #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther - #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index 4970b140a..24754d8fa 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -273,7 +273,12 @@ procsSqlQuery pgVer = [q| type::regtype::text, -- type idx <= (pronargs - pronargdefaults), -- is_required COALESCE(mode = 'v', FALSE) -- is_variadic - ) ORDER BY idx) AS args + ) ORDER BY idx) AS args, + CASE COUNT(*) - COUNT(name) -- number of unnamed arguments + WHEN 0 THEN true + WHEN 1 THEN (array_agg(type))[1] IN ('bytea'::regtype, 'json'::regtype, 'jsonb'::regtype, 'text'::regtype) + ELSE false + END AS callable FROM pg_proc, unnest(proargnames, proargtypes, proargmodes) WITH ORDINALITY AS _ (name, type, mode, idx) @@ -303,7 +308,7 @@ procsSqlQuery pgVer = [q| JOIN pg_namespace tn ON tn.oid = t.typnamespace LEFT JOIN pg_class comp ON comp.oid = t.typrelid LEFT JOIN pg_description as d ON d.objoid = p.oid - WHERE t.oid <> 'trigger'::regtype + WHERE t.oid <> 'trigger'::regtype AND COALESCE(a.callable, true) |] <> (if pgVer >= pgVersion110 then "AND prokind = 'f'" else "AND NOT (proisagg OR proiswindow)") schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)