Skip to content

fix(settings): fall back to local default when DATABASE_URL is empty - #5235

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/settings-empty-database-url-fallback-w1
Jul 24, 2026
Merged

fix(settings): fall back to local default when DATABASE_URL is empty#5235
pedrofrxncx merged 1 commit into
mainfrom
fix/settings-empty-database-url-fallback-w1

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Bug found while auditing apps/api/src/settings/ for environment-fallback edge cases (a lot of similar ??-vs-|| bugs in this area were fixed in recent PRs like #5173, #5177, #5191, #5213, #5217).

Failure scenario: getSettings()'s child-process auto-init path (apps/api/src/settings/index.ts, initSettingsFromEnv) resolves databaseUrl with envVars.DATABASE_URL ?? "postgresql://postgres:postgres@localhost:5432/postgres". ?? only falls back on null/undefined — if DATABASE_URL is explicitly set but empty (e.g. a templated deploy env var left unfilled), the empty string flows straight through as the connection string instead of falling back to the documented local default. The very next field in the same object (natsUrls) already uses || for this exact reason, and every field in the sibling resolve-config.ts follows the same || default convention — this one line was the odd one out.

Fix: change ?? to ||, matching the established convention.

Regression test: apps/api/src/settings/index.test.ts sets DATABASE_URL="" and asserts getSettings().databaseUrl resolves to the local default. Verified this test fails on the old code (Received: "") and passes with the fix.

To verify: bun test apps/api/src/settings/index.test.ts

Checks run locally: bun run fmt, cd apps/api && bunx tsc --noEmit, and the targeted test file above (plus the full resolve-config.test.ts suite, still 58/58 green). Full CI validates the rest.


Summary by cubic

Fixes settings init to fall back to the local default database URL when DATABASE_URL is set to an empty string. Switched ?? to || in apps/api/src/settings/index.ts and added a regression test to lock this behavior.

Written for commit d5b9d35. Summary will update on new commits.

Review in cubic

getSettings()'s auto-init path used `envVars.DATABASE_URL ?? default`, so an
explicitly-set but empty DATABASE_URL (e.g. a templated env var left
unfilled) flowed through as an empty connection string instead of falling
back to the documented local default. Every other env-fallback in this file
(natsUrls right below it, and every field in resolve-config.ts) uses `||`
for exactly this reason. Match that convention.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 24, 2026 22:00
@pedrofrxncx
pedrofrxncx merged commit 9e2fbe1 into main Jul 24, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/settings-empty-database-url-fallback-w1 branch July 24, 2026 22:02
decocms Bot pushed a commit that referenced this pull request Jul 24, 2026
PR: #5235 fix(settings): fall back to local default when DATABASE_URL is empty
Bump type: patch

- decocms (apps/api/package.json): 4.126.1 -> 4.126.2

Deploy-Scope: server
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.

1 participant