Skip to content

Commit

Permalink
Fix handling of empty application_name
Browse files Browse the repository at this point in the history
It was reported in #993 that using an empty `application_name` on
connection startup could result in the actual application_name that was
set later not being detected. The reason was that we were explicitely
not forwarding empty strings from clients as settings to Postgres. This
is fixed by simply removing this check. Why we were explicitely ignoring
empty strings is not clear to me. But our handling of startup parameters
and GUCs has heavily changed over the years, and is able to handle them
fine like this.
  • Loading branch information
JelteF committed Dec 22, 2023
1 parent 5e5871a commit 94f4dc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/varcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int apply_var(PktBuf *pkt, const char *key,
const char *tmp;

/* if unset, skip */
if (!cval || !sval || !*cval->str)
if (!cval || !sval)
return 0;

/* if equal, skip */
Expand Down
12 changes: 12 additions & 0 deletions test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,15 @@ def test_options_startup_param(bouncer):
)
== "Portugal"
)


def test_empty_application_name(bouncer):
with bouncer.cur(dbname="p1", application_name="") as cur:
assert cur.execute("SHOW application_name").fetchone()[0] == ""
cur.execute("SET application_name = test")
assert cur.execute("SHOW application_name").fetchone()[0] == "test"

with bouncer.cur(dbname="p1", application_name="") as cur:
assert cur.execute("SHOW application_name").fetchone()[0] == ""
cur.execute("SET application_name = test")
assert cur.execute("SHOW application_name").fetchone()[0] == "test"

0 comments on commit 94f4dc0

Please sign in to comment.