From 87c04f12073f85ae827ce1844a5094b5ee2c3d71 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Fri, 10 Jul 2026 15:50:00 -0500 Subject: [PATCH] Don't clobber caller's client_min_messages on install (#4) The install script began with an unconditional `SET LOCAL client_min_messages = WARNING`. Because CREATE EXTENSION runs the whole script in a single transaction, that SET LOCAL applied for the entire statement -- including any CASCADE that pulls object_reference in as a dependency -- silently overriding a caller who had deliberately set a stricter level (e.g. `SET client_min_messages = error`) to keep install output quiet. Replace it with a DO block that only raises the floor to WARNING when the caller's current level is more verbose than WARNING; a stricter level (warning/error) is left untouched. SET LOCAL inside the DO block still applies to the rest of the CREATE EXTENSION transaction and reverts at commit, so it never leaks into the caller's session. Verified on PostgreSQL 12: with the caller at ERROR the setting is preserved through CREATE EXTENSION; at NOTICE the install runs quiet and the caller's NOTICE level is restored after commit. The zzz_build expected output is regenerated via `make results` (line-number shifts only, from adding the guard block at the top of the file). Co-Authored-By: Claude Opus 4.8 (1M context) --- sql/object_reference--0.2.0.sql | 34 ++++++++++++++++++++++++++++++++- sql/object_reference.sql | 34 ++++++++++++++++++++++++++++++++- test/expected/zzz_build.out | 10 +++++----- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/sql/object_reference--0.2.0.sql b/sql/object_reference--0.2.0.sql index eaab900..d522812 100644 --- a/sql/object_reference--0.2.0.sql +++ b/sql/object_reference--0.2.0.sql @@ -1,5 +1,37 @@ /* DO NOT EDIT - AUTO-GENERATED FILE */ -SET LOCAL client_min_messages = WARNING; +/* + * Quiet the NOTICEs this install script emits (e.g. duplicate CREATE ROLE) + * without overriding a caller who has deliberately asked for even less output. + * + * CREATE EXTENSION runs the whole script in one transaction, so a blind + * `SET LOCAL client_min_messages = WARNING` clobbers the caller's setting for + * the entire statement -- including any CASCADE that pulls this extension in + * as a dependency (see issue #4). A caller who set a stricter level such as + * ERROR to keep install output quiet would be silently overridden. + * + * Instead only raise the floor to WARNING; never lower it below the level the + * caller chose. SET LOCAL inside a DO block still applies to the rest of the + * (CREATE EXTENSION) transaction, and reverts at commit so it does not leak + * into the caller's session. + */ +DO $$ +DECLARE + -- client_min_messages levels ordered least-to-most severe (LOG sorts + -- between DEBUG1 and NOTICE for this GUC). + c_levels CONSTANT text[] := ARRAY[ + 'debug5', 'debug4', 'debug3', 'debug2', 'debug1' + , 'log', 'notice', 'warning', 'error' + ]; +BEGIN + IF pg_catalog.array_position( + c_levels + , pg_catalog.lower(pg_catalog.current_setting('client_min_messages')) + ) < pg_catalog.array_position(c_levels, 'warning') + THEN + SET LOCAL client_min_messages = warning; + END IF; +END +$$; \echo This extension must be loaded via 'CREATE EXTENSION object_reference;' \echo You really, REALLY do NOT want to try and load this via psql!!! \echo It will FAIL during pg_dump! \quit diff --git a/sql/object_reference.sql b/sql/object_reference.sql index 6aeb197..6391955 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1,4 +1,36 @@ -SET LOCAL client_min_messages = WARNING; +/* + * Quiet the NOTICEs this install script emits (e.g. duplicate CREATE ROLE) + * without overriding a caller who has deliberately asked for even less output. + * + * CREATE EXTENSION runs the whole script in one transaction, so a blind + * `SET LOCAL client_min_messages = WARNING` clobbers the caller's setting for + * the entire statement -- including any CASCADE that pulls this extension in + * as a dependency (see issue #4). A caller who set a stricter level such as + * ERROR to keep install output quiet would be silently overridden. + * + * Instead only raise the floor to WARNING; never lower it below the level the + * caller chose. SET LOCAL inside a DO block still applies to the rest of the + * (CREATE EXTENSION) transaction, and reverts at commit so it does not leak + * into the caller's session. + */ +DO $$ +DECLARE + -- client_min_messages levels ordered least-to-most severe (LOG sorts + -- between DEBUG1 and NOTICE for this GUC). + c_levels CONSTANT text[] := ARRAY[ + 'debug5', 'debug4', 'debug3', 'debug2', 'debug1' + , 'log', 'notice', 'warning', 'error' + ]; +BEGIN + IF pg_catalog.array_position( + c_levels + , pg_catalog.lower(pg_catalog.current_setting('client_min_messages')) + ) < pg_catalog.array_position(c_levels, 'warning') + THEN + SET LOCAL client_min_messages = warning; + END IF; +END +$$; \echo This extension must be loaded via 'CREATE EXTENSION object_reference;' \echo You really, REALLY do NOT want to try and load this via psql!!! \echo It will FAIL during pg_dump! \quit diff --git a/test/expected/zzz_build.out b/test/expected/zzz_build.out index ff07ade..6b55381 100644 --- a/test/expected/zzz_build.out +++ b/test/expected/zzz_build.out @@ -2,16 +2,16 @@ This extension must be loaded via CREATE EXTENSION object_reference; You really, REALLY do NOT want to try and load this via psql!!! -psql:test/temp_load.not_sql:159: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:191: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:160: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:192: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:414: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:446: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! @@ -21,9 +21,9 @@ psql:test/temp_load.not_sql:414: WARNING: I promise you will be sorry if you tr -psql:test/temp_load.not_sql:521: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:553: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:528: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:560: WARNING: I promise you will be sorry if you try to use this as anything other than an extension!