Use the config key Rails documents, so a local run comes back clean
Credit: this is @jaysbeekay's fix, ported unchanged from their fork: jaysbeekay/sure#196 (commit f7c5bb573), which resolved jaysbeekay/sure#168. It never reached this repository, so upstream main still has the bug. The commit keeps @jaysbeekay as author and their original message.
Problem
config/database.yml sets user:, but Rails' key is username:. The PostgreSQL adapter passes unrecognised keys through to libpq, which understands user, so the app connects fine and nothing looks wrong. But configuration_hash has :user and no :username.
RecurringTransaction::PipelineTest "run_with_lock! refuses to stack on a held family lock" opens a separate PG session and reads config[:username]. That's nil, gets dropped by .compact, and libpq falls back to the OS user. In the devcontainer that's root:
PG::ConnectionBad: ... FATAL: password authentication failed for user "root"
CI is green only because ci.yml sets PGUSER (and DATABASE_URL). Other contributors have been noting this error as "environmental" in their PRs (e.g. #3608, #3916).
Change
config/database.yml:user:→username:. The adapter maps it to libpq'suseritself, so the app's connection is unchanged.configuration_hashhas one reader in the repo (this test), and nothing templatesdatabase.yml; compose files, the chart and the docs setPOSTGRES_USERas an env var.- Two guard tests in
pipeline_test.rb:- one asserts the
database.ymlfile itself usesusername:(CI'sDATABASE_URLhides the key in the resolved config); - one checks the resolved config, skipped when
DATABASE_URLis set.
- one asserts the
- As jaysbeekay explains, this deliberately does not fall back to
config[:username] || config[:user]in the test. That fallback would hide a regression of the key, which is how this bug went unnoticed. An earlier revision of this PR did use that fallback; it's replaced by this fix.
Validation (devcontainer, no DATABASE_URL)
pipeline_test.rb: 6 runs, 0 failures, 0 errors.- Temporarily reverting the key to
user:: both guard tests fail ("database.yml must useusername:…") and the lock test errors as before. - Full
bin/rails test: 10431 runs, 0 failures, 1 error. The one error is the date-dependentReportsControllerTestfailure from #3908, which #3902 fixes; this PR doesn't touch it. bin/rubocopon the test file: no offenses.
Refs #3908. Together with #3902, this resolves it.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Configuration
- PostgreSQL connections now use the
usernamesetting, sourced fromPOSTGRES_USERand defaulting tonil. The previoususersetting is no longer used in the default database configuration.
- PostgreSQL connections now use the
- Tests
- Added checks to confirm the default configuration and resolved connection settings use
usernamerather thanuser. The resolved-settings check is skipped whenDATABASE_URLis set.
- Added checks to confirm the default configuration and resolved connection settings use