034 — Store Backend Auto-Fallback (store_backend="auto")¶
Status: ACCEPTED Date: 2026-06-18 Extends: 020-registry-fallback-named-backend.md
Context¶
Settings.store_backend defaults to "postgres" (config.py:18). The
validate_postgres_dsn model validator (line 192-200) raises ValueError at
construction time if store_dsn is empty. Concretely:
python -c "from job_ftch.config import Settings; print(Settings().store_backend)"raises before printing, because Settings() with no env cannot materialise a DSN.uv run job_ftch --helpgoes throughget_settings()incli.py:530and fails.- New users following the README quickstart without a Postgres DSN in
.env.devcannot run any command, including--help,eval, ortest.
ADR-020 already routed the error-fallback path through the named registry
(create_store_with_fallback(settings) resolves the fallback store by name
"memory"). But the happy-path default still demands a real Postgres DSN.
The two paths are inconsistent: a failing Postgres silently falls back to
memory, but a healthy dev box with no Postgres at all cannot even initialise
Settings.
The fix is the same shape ADR-020 used: route the default through a named resolution function, never a hard-coded "postgres" string in Settings.
Decision¶
Settings.store_backenddefault becomes"auto"(was"postgres").Settings.store_backendaccepts the values"auto","postgres","sqlite","memory", plus any backend name registered via@register_store.validate_postgres_dsnis removed. Instead, the validator only warns (log.warning) whenstore_backend="postgres"and DSN is empty.- New
resolve_store_backend(settings) -> strinapplication/registry.py: - If
store_backendis one of the explicit names, return it as-is. - If
store_backend == "auto":- If
store_dsnis set and the DSN parses as a real URL → return"postgres". - Else if
JOB_FTCH_SQLITE_PATHenv or./data/jobs.dbis writable → return"sqlite". - Else return
"memory".
- If
- Resolution is logged at
INFOlevel:resolved store_backend=… from auto. create_store_with_fallback(ADR-020) keeps its error-fallback role for runtime failures (e.g., Postgres is reachable at construction but goes down mid-run).Settings()instantiates without env, souv run job_ftch --helpworks.- The five adapter CLIs (
telegram_bot,mcp,fastapi,faststream,dagster) inherit the same auto-resolution viaget_settings().
Consequences¶
- (+) Zero-config onboarding:
uv run job_ftch --help,eval,testall work with no.envfile. Memory store is the silent default for ephemeral runs. - (+) Production stays explicit: operators set
JOB_FTCH_STORE_BACKEND=postgresand a real DSN; no accidental fallback to memory. - (+) ADR-020's named-fallback discipline is now the only path — no special
import in
application/registry.py, no hardcoded default inSettings. - (-) One more env var (
JOB_FTCH_SQLITE_PATH) to document. - (-) Operators who relied on the
ValueErrorto catch missing DSN config will now see a silent fallback. Mitigated byINFO-level log on every run. - (-) Tests that asserted on
Settings(store_backend="postgres")construction failure need to switch to asserting on resolution viaresolve_store_backend.