Skip to content

Fix silent settings fallback in alembic env.py#62

Open
ZechCodes wants to merge 1 commit intomainfrom
fix/alembic-silent-fallback
Open

Fix silent settings fallback in alembic env.py#62
ZechCodes wants to merge 1 commit intomainfrom
fix/alembic-silent-fallback

Conversation

@ZechCodes
Copy link
Copy Markdown
Owner

Summary

  • Bug: When get_settings() throws an exception in alembic/env.py (e.g. missing REDIS_URL or other env vars), get_url() silently falls back to the alembic.ini default (sqlite+aiosqlite:///./app.db) and get_schema() silently returns None. Migrations then run against SQLite instead of the configured Postgres database with zero warning.
  • Fix: Add logger.warning(..., exc_info=True) to both get_url() and get_schema() exception handlers so the fallback is visible and the root cause exception is logged.
  • Docs: Add a comment documenting the known Alembic <=1.18 limitation where depends_on cross-location references cause RevisionError: Requested revision X overlaps with other requested revisions Y when running upgrade heads.

Test plan

  • Verify that with valid env vars, skrift db upgrade heads works as before (no warnings emitted)
  • Verify that with a missing env var (e.g. unset REDIS_URL), the warning is now logged to stderr before the fallback URL is used
  • Verify the warning includes the full traceback (exc_info=True)

🤖 Generated with Claude Code

When get_settings() throws (e.g. missing REDIS_URL), get_url() silently
returns the alembic.ini fallback URL (SQLite) and get_schema() silently
returns None. This causes migrations to run against SQLite instead of
the configured Postgres database with no indication anything went wrong.

Add warning-level logging with exc_info to both get_url() and
get_schema() so the root cause is visible when the fallback triggers.

Also document the known Alembic <=1.18 limitation where depends_on
cross-location references cause RevisionError on "upgrade heads".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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