From 580fe779dd2ff051d3c0a06e2a6221aeb1a3c3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Loipf=C3=BChrer?= Date: Mon, 29 Dec 2025 18:33:22 +0100 Subject: [PATCH] fix(sftkit): filter out database functions belonging to postgres user / loaded extensions See https://github.com/SFTtech/abrechnung/pull/300 --- sftkit/src/sftkit/database/introspection/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sftkit/src/sftkit/database/introspection/__init__.py b/sftkit/src/sftkit/database/introspection/__init__.py index 0a20065..6e561c5 100644 --- a/sftkit/src/sftkit/database/introspection/__init__.py +++ b/sftkit/src/sftkit/database/introspection/__init__.py @@ -37,10 +37,15 @@ class PgFunctionDef(BaseModel): async def list_functions(conn: Connection, schema: str) -> list[PgFunctionDef]: + """ + List all functions which are owned by the current database user and do not belong to any extension. + """ return await conn.fetch_many( PgFunctionDef, - "select pg_proc.*, pg_get_function_identity_arguments(oid) as signature from pg_proc " - "where pronamespace = $1::regnamespace and pg_proc.proname !~ '^pg_';", + "select p.*, pg_get_function_identity_arguments(p.oid) as signature from pg_proc as p " + "join pg_authid as a on p.proowner = a.oid " + "where p.pronamespace = $1::regnamespace and a.rolname = CURRENT_USER " + " and not exists(select from pg_depend as d where d.objid = p.oid and d.deptype = 'e')", schema, )