You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This has two failure modes for any non-PostgreSQL connection:
Silently broken for MS-SQL: an mssql:// DSN passes through unchanged and is handed to create_async_engine, which then fails with a confusing dialect error rather than a clear message.
Silently broken when a driver is already specified: a DSN such as postgresql+psycopg2://... does not match the literal postgresql:// prefix, so the replace is a no-op and the sync driver is passed to the async engine.
Proposed steps
Introduce a make_async_dsn(db_dsn: str) -> str helper that parses the DSN with SQLAlchemy's make_url, extracts the dialect (the portion before any +), and rewrites the drivername component using a lookup table:
This correctly handles postgresql://, postgresql+psycopg2://, mssql://, and mssql+pyodbc:// — and raises a clear ValueError for unknown dialects instead of producing a silent no-op.
Replace the call site in create_db_engine (datafaker/utils.py):
Summary
The async connection string is built by a hardcoded string replacement in
datafaker/utils.py:This has two failure modes for any non-PostgreSQL connection:
mssql://DSN passes through unchanged and is handed tocreate_async_engine, which then fails with a confusing dialect error rather than a clear message.postgresql+psycopg2://...does not match the literalpostgresql://prefix, so the replace is a no-op and the sync driver is passed to the async engine.Proposed steps
Introduce a
make_async_dsn(db_dsn: str) -> strhelper that parses the DSN with SQLAlchemy'smake_url, extracts the dialect (the portion before any+), and rewrites thedrivernamecomponent using a lookup table:This correctly handles
postgresql://,postgresql+psycopg2://,mssql://, andmssql+pyodbc://— and raises a clearValueErrorfor unknown dialects instead of producing a silent no-op.Replace the call site in
create_db_engine(datafaker/utils.py):Add
aioodbcas an optional dependency (see Add MS-SQL driver support (pyodbc/pymssql) #93) for themssqlextra so the async MS-SQL driver is available when needed.Add unit tests covering:
postgresql://→postgresql+asyncpg://postgresql+psycopg2://→postgresql+asyncpg://mssql://→mssql+aioodbc://mssql+pyodbc://→mssql+aioodbc://ValueErrorAcceptance criteria
create_db_engineproduces a valid async DSN for bothpostgresql://andmssql://connection strings.postgresql+psycopg2://) is correctly rewritten rather than silently passed through.ValueErrorwith a message naming the dialect.Related
pyodbc/aioodbc)