From ba6a61a5bf0ea2dd631552ba50b2c7ad614f155b Mon Sep 17 00:00:00 2001 From: ang3l12 Date: Mon, 13 Jul 2026 13:58:06 -0600 Subject: [PATCH] Fix alembic env crashing on URL-encoded password characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passing the DB URL through config.set_main_option() runs it through ConfigParser, which treats '%' as interpolation syntax — so any password character that URL-encodes to %xx ('!', '@', '#', ...) crashed migrations ('invalid interpolation syntax'). Build the engine directly from the URL instead of routing it through the ini config. Co-Authored-By: Claude Fable 5 --- backend/alembic/env.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/alembic/env.py b/backend/alembic/env.py index 4a21870..31cfa7a 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -1,7 +1,7 @@ from logging.config import fileConfig from alembic import context -from sqlalchemy import engine_from_config, pool +from sqlalchemy import create_engine, pool from app.config import get_settings from app.models import Base @@ -10,13 +10,15 @@ config = context.config if config.config_file_name is not None: fileConfig(config.config_file_name) -config.set_main_option("sqlalchemy.url", get_settings().sync_database_url) +# The database URL is passed directly to SQLAlchemy rather than through +# config.set_main_option(): ConfigParser treats '%' as interpolation syntax, +# so URL-encoded password characters (e.g. '!' -> '%21') would blow up. target_metadata = Base.metadata def run_migrations_offline() -> None: context.configure( - url=config.get_main_option("sqlalchemy.url"), + url=get_settings().sync_database_url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, @@ -26,15 +28,14 @@ def run_migrations_offline() -> None: def run_migrations_online() -> None: - connectable = engine_from_config( - config.get_section(config.config_ini_section, {}), - prefix="sqlalchemy.", - poolclass=pool.NullPool, + connectable = create_engine( + get_settings().sync_database_url, poolclass=pool.NullPool ) with connectable.connect() as connection: context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations() + connectable.dispose() if context.is_offline_mode():