diff --git a/app/core/db/__init__.py b/app/core/db/__init__.py index 1967a19..01604f3 100644 --- a/app/core/db/__init__.py +++ b/app/core/db/__init__.py @@ -86,6 +86,21 @@ def get_session_factory() -> async_sessionmaker[AsyncSession]: return _session_factory +# Backward-compat alias: code imports `async_session_maker` from app.core.db. +# Behaves like the session factory — calling it returns an AsyncSession. +# We use a wrapper class so `async with async_session_maker() as db:` works. +class _AsyncSessionMakerWrapper: + """Lazy proxy for the global async_sessionmaker.""" + def __call__(self) -> AsyncSession: + return get_session_factory()() + + def __getattr__(self, name: str) -> Any: + return getattr(get_session_factory(), name) + + +async_session_maker = _AsyncSessionMakerWrapper() + + async def get_db() -> AsyncGenerator[AsyncSession, None]: """FastAPI dependency: yield an async database session.""" factory = get_session_factory()