fix: add async_session_maker alias in db/__init__.py for plugin imports
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user