asyncgenerator fix
This commit is contained in:
@@ -139,14 +139,14 @@ This example shows the ownership boundaries. Adapt state storage and dependency
|
||||
|
||||
```python
|
||||
from contextlib import AsyncExitStack, asynccontextmanager
|
||||
from collections.abc import AsyncIterator
|
||||
from collections.abc import AsyncGeneratorr
|
||||
|
||||
from fastapi import FastAPI
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
|
||||
async with AsyncExitStack() as stack:
|
||||
engine = create_async_engine(settings.database_url)
|
||||
stack.push_async_callback(engine.dispose)
|
||||
@@ -160,7 +160,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
yield
|
||||
|
||||
|
||||
async def get_session() -> AsyncIterator[AsyncSession]:
|
||||
async def get_session() -> AsyncGenerator[AsyncSession]:
|
||||
async with app.state.session_factory() as session:
|
||||
yield session
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user