Skip to content

fix: whoami regression to anonymous user#4303

Open
lsunsi wants to merge 1 commit into
transact-rs:mainfrom
lsunsi:whoami-feature-std
Open

fix: whoami regression to anonymous user#4303
lsunsi wants to merge 1 commit into
transact-rs:mainfrom
lsunsi:whoami-feature-std

Conversation

@lsunsi

@lsunsi lsunsi commented Jun 9, 2026

Copy link
Copy Markdown

Does your PR solve an issue?

Fixes #4277

Is this a breaking change?

No, just a bug fix.

Reference

This PR is just a rehash of #4275 from @svnrb.
I just re-opened this PR because he said he was gonna be away for 2 weeks and I have so time to maybe move this along!


#[test]
#[cfg(all(unix, not(target_arch = "wasm32")))]
fn it_uses_the_os_username_when_url_omits_user() {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abonander @svnrb

I didn't copy the Mutex bit because I didn't understand why it was needed. This test was enough to fail without the fix, so I think it could work as the regression test needed and avoid a separate CI step.

What do you think? If the mutex was really needed, do you mind explaining why?

@svnrb

svnrb commented Jun 9, 2026 via email

Copy link
Copy Markdown

@lsunsi

lsunsi commented Jun 9, 2026

Copy link
Copy Markdown
Author

@svnrb Got it, thanks for clarifying. One question, how about we read the PG_USER during the test in order to assert it's not set? Then if there would be any interference, this "precondition" assert would fail and it wouldn't go unnoticed. It's less complex than changing the env, and safer than current implementation. What do you think?

Further, we could assert the PGUSER env is none or different from what we receive from the parsing, for example. Just throwing ideas

@svnrb

svnrb commented Jun 9, 2026 via email

Copy link
Copy Markdown

@lsunsi

lsunsi commented Jun 9, 2026

Copy link
Copy Markdown
Author

@svnrb Got it, you're right. So we'll wait on the @abonander direction and I'll fix this PR right up. (:

@abonander

Copy link
Copy Markdown
Collaborator

env::set_var() is unsafe in the 2024 edition because it's unsound to set and read environment variables concurrently under glibc.

dotenvy has actually been undergoing a major rewrite for this reason; the API that's on main is very different from the last release: https://github.com/allan2/dotenvy#modifying-api

Ideally, I think we add a CI step that runs the postgres integration test relying on this functionality, but that would require setting up a user either in the GHA environment to match the Postgres user or vice-versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlx-cli regression in 0.9.0: role "anonymous" does not exist

3 participants