asyncgenerator fix

This commit is contained in:
John Lancaster
2026-07-30 20:51:16 -05:00
parent 70695ff218
commit 1ed5856db0
6 changed files with 19 additions and 19 deletions
@@ -130,7 +130,7 @@ Otherwise, a later call can return a maker that still references the old engine
A small [`asynccontextmanager`](https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager) can make repository methods composable. It borrows an existing session when supplied; otherwise it creates and closes one from a supplied factory:
```python
from collections.abc import AsyncIterator
from collections.abc import AsyncGeneratorr
from contextlib import asynccontextmanager
@@ -139,7 +139,7 @@ async def session_scope(
*,
database_url: str,
session: AsyncSession | None = None,
) -> AsyncIterator[AsyncSession]:
) -> AsyncGenerator[AsyncSession]:
if session is not None:
yield session
return
@@ -172,7 +172,7 @@ async def transaction_scope(
*,
database_url: str,
session: AsyncSession | None = None,
) -> AsyncIterator[AsyncSession]:
) -> AsyncGenerator[AsyncSession]:
if session is not None:
if not session.in_transaction():
raise RuntimeError("A supplied session must have an active transaction")
@@ -277,7 +277,7 @@ This preserves atomicity without making repository objects hold mutable `AsyncSe
## Canonical FastAPI Dependency Pattern
```python
from collections.abc import AsyncIterator
from collections.abc import AsyncGenerator
from fastapi import Depends
from fastapi import Request
@@ -294,7 +294,7 @@ def resolve_session_factory(request: Request) -> SessionFactory:
async def get_db_session(
session_factory: SessionFactory = Depends(resolve_session_factory),
) -> AsyncIterator[AsyncSession]:
) -> AsyncGenerator[AsyncSession]:
async with session_factory() as session:
yield session
```