Bug in Configuration Setting Functions after a Commit

Started by João felipe Chiarelli Bourscheidabout 1 year ago4 messagesbugs
Jump to latest
#1João felipe Chiarelli Bourscheid
joao.felipe.c.b@gmail.com

Hello:

I'm enthusiastic about the PostgreSQL project and this is my first bug
report. Please apologize if I'm on the wrong channel.

The bug is the following: when I set a custom variable using the
configuration settings functions within a transaction, after I commit the
transaction, instead of the variable becoming null, it becomes an empty
string.

How to reproduce:

SELECT current_setting('custom.user_id', true)::INTEGER; -- NULL

BEGIN;

SELECT set_config('custom.user_id', '2', true);

SELECT current_setting('custom.user_id', true)::INTEGER; -- 2

END;

SELECT current_setting('custom.user_id', true)::INTEGER; -- Empty string
instead of null

PostgreSQL version: PostgreSQL 15.10 (Debian 15.10-0+deb12u1) on
x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: João felipe Chiarelli Bourscheid (#1)
Re: Bug in Configuration Setting Functions after a Commit

On Mon, Feb 24, 2025 at 11:32 AM João felipe Chiarelli Bourscheid <
joao.felipe.c.b@gmail.com> wrote:

The bug is the following: when I set a custom variable using the
configuration settings functions within a transaction, after I commit the
transaction, instead of the variable becoming null, it becomes an empty
string.

Yes, this is working as designed. The variable will never take on the null
value, and the system won't forget that it exists once created, so the
default value of empty string is restored when the transaction ends.

There is some work-in-progress to clarify this in the documentation.

David J.

#3João felipe Chiarelli Bourscheid
joao.felipe.c.b@gmail.com
In reply to: David G. Johnston (#2)
Re: Bug in Configuration Setting Functions after a Commit

Thanks, is there a way that I can help contrinuting to writing this into
the documentation? Should I refer to pgsql-docs@lists.postgresql.org ?

Em seg., 24 de fev. de 2025 15:38, David G. Johnston <
david.g.johnston@gmail.com> escreveu:

Show quoted text

On Mon, Feb 24, 2025 at 11:32 AM João felipe Chiarelli Bourscheid <
joao.felipe.c.b@gmail.com> wrote:

The bug is the following: when I set a custom variable using the
configuration settings functions within a transaction, after I commit the
transaction, instead of the variable becoming null, it becomes an empty
string.

Yes, this is working as designed. The variable will never take on the
null value, and the system won't forget that it exists once created, so the
default value of empty string is restored when the transaction ends.

There is some work-in-progress to clarify this in the documentation.

David J.

#4David G. Johnston
david.g.johnston@gmail.com
In reply to: João felipe Chiarelli Bourscheid (#3)
Re: Bug in Configuration Setting Functions after a Commit

On Mon, Feb 24, 2025 at 11:49 AM João felipe Chiarelli Bourscheid <
joao.felipe.c.b@gmail.com> wrote:

Thanks, is there a way that I can help contrinuting to writing this into
the documentation? Should I refer to pgsql-docs@lists.postgresql.org ?

I have targeted commitfest entry for this issue here:

https://commitfest.postgresql.org/patch/5548/

And a larger rework regarding NULL here that covers this topic briefly
since it is a bit unintuitive that settings may not take on a null value;
while current_setting can return NULL as an error-substitute sentinel value.

https://commitfest.postgresql.org/patch/5086/

Reviewing them would be very helpful.

David J.