Skip to content

Commit 9e0bc0b

Browse files
committed
fix(e2e): convert database URLs to async driver format
Add _convert_to_async_url helper to convert sync database URLs (postgresql://, mysql://, sqlite://) to their async equivalents (postgresql+asyncpg://, mysql+aiomysql://, sqlite+aiosqlite://). This fixes the E2E tests in CI where the DATABASE_URL env var uses the sync format but SQLAlchemy's create_async_engine requires the async driver format.
1 parent 5444614 commit 9e0bc0b

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

tests/e2e/conftest.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from db.schema import ColumnInfo, SchemaInfo, TableInfo
2525
from tests.e2e.seed_data import E2E_TEST_DATA, seed_database
2626

27-
2827
# =============================================================================
2928
# Event Loop Fixture for Module-Scoped Async Fixtures
3029
# =============================================================================
@@ -87,6 +86,17 @@ def pytest_configure(config: Any) -> None:
8786
# =============================================================================
8887

8988

89+
def _convert_to_async_url(url: str) -> str:
90+
"""Convert a sync database URL to async format."""
91+
if url.startswith("postgresql://"):
92+
return url.replace("postgresql://", "postgresql+asyncpg://", 1)
93+
elif url.startswith("mysql://"):
94+
return url.replace("mysql://", "mysql+aiomysql://", 1)
95+
elif url.startswith("sqlite://"):
96+
return url.replace("sqlite://", "sqlite+aiosqlite://", 1)
97+
return url
98+
99+
90100
@pytest_asyncio.fixture(scope="module")
91101
async def e2e_engine() -> AsyncGenerator[Any, None]:
92102
"""
@@ -97,15 +107,18 @@ async def e2e_engine() -> AsyncGenerator[Any, None]:
97107
"""
98108
db_url = get_e2e_database_url()
99109

110+
# Convert to async URL if needed
111+
async_url = _convert_to_async_url(db_url)
112+
100113
engine_kwargs: dict[str, Any] = {
101114
"echo": False,
102115
}
103116

104-
if "sqlite" in db_url:
117+
if "sqlite" in async_url:
105118
engine_kwargs["connect_args"] = {"check_same_thread": False}
106119
engine_kwargs["poolclass"] = StaticPool
107120

108-
engine = create_async_engine(db_url, **engine_kwargs)
121+
engine = create_async_engine(async_url, **engine_kwargs)
109122

110123
yield engine
111124

@@ -316,11 +329,22 @@ async def e2e_registry(
316329
# Create new registry
317330
registry = DatabaseRegistry()
318331

319-
# Create config with in-memory SQLite
332+
# Create config - use async URL for proper driver loading
333+
db_url = get_e2e_database_url()
334+
async_url = _convert_to_async_url(db_url)
335+
336+
# Detect dialect from URL
337+
if "postgresql" in db_url:
338+
dialect = SQLDialect.POSTGRESQL
339+
elif "mysql" in db_url:
340+
dialect = SQLDialect.MYSQL
341+
else:
342+
dialect = SQLDialect.SQLITE
343+
320344
config = DatabaseConfig(
321345
database_id="e2e_test",
322-
connection_string=get_e2e_database_url(),
323-
dialect=SQLDialect.SQLITE,
346+
connection_string=async_url,
347+
dialect=dialect,
324348
display_name="E2E Test Database",
325349
description="Database for end-to-end testing",
326350
)

0 commit comments

Comments
 (0)