Skip to content

Commit a78c968

Browse files
jnasbyupgradeclaude
andcommitted
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. Note: the zzz_build test echoes the install script with source line numbers, so its expected output shifts by the number of lines this block adds (+32). It could not be regenerated in place here because master does not build on modern PostgreSQL with the pgxn-provided cat_tools; regenerate expected output in the canonical CI environment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d191ef1 commit a78c968

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

sql/object_reference.sql

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
SET LOCAL client_min_messages = WARNING;
1+
/*
2+
* Quiet the NOTICEs this install script emits (e.g. duplicate CREATE ROLE)
3+
* without overriding a caller who has deliberately asked for even less output.
4+
*
5+
* CREATE EXTENSION runs the whole script in one transaction, so a blind
6+
* `SET LOCAL client_min_messages = WARNING` clobbers the caller's setting for
7+
* the entire statement -- including any CASCADE that pulls this extension in
8+
* as a dependency (see issue #4). A caller who set a stricter level such as
9+
* ERROR to keep install output quiet would be silently overridden.
10+
*
11+
* Instead only raise the floor to WARNING; never lower it below the level the
12+
* caller chose. SET LOCAL inside a DO block still applies to the rest of the
13+
* (CREATE EXTENSION) transaction, and reverts at commit so it does not leak
14+
* into the caller's session.
15+
*/
16+
DO $$
17+
DECLARE
18+
-- client_min_messages levels ordered least-to-most severe (LOG sorts
19+
-- between DEBUG1 and NOTICE for this GUC).
20+
c_levels CONSTANT text[] := ARRAY[
21+
'debug5', 'debug4', 'debug3', 'debug2', 'debug1'
22+
, 'log', 'notice', 'warning', 'error'
23+
];
24+
BEGIN
25+
IF pg_catalog.array_position(
26+
c_levels
27+
, pg_catalog.lower(pg_catalog.current_setting('client_min_messages'))
28+
) < pg_catalog.array_position(c_levels, 'warning')
29+
THEN
30+
SET LOCAL client_min_messages = warning;
31+
END IF;
32+
END
33+
$$;
234
\echo This extension must be loaded via 'CREATE EXTENSION object_reference;'
335
\echo You really, REALLY do NOT want to try and load this via psql!!!
436
\echo It will FAIL during pg_dump! \quit

0 commit comments

Comments
 (0)