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
I am trying to globally initialize a DB instance using asynccontextmanager in my FastAPI backend server and access it during API requests. When I run the Reflex app, the lifespan code executes, but the value is not stored in the request's state. Is there a different way to execute the code correctly?
generally speaking only the outer-most ASGI app runs the lifespan. So in your case, app in the lifespan is Reflex's outer Starlette app, not your FastAPI app.
as a workaround you can probably look through the starlette mounts, find the FastAPI instance, and assign your db to that.
Activity
masenf commentedon Oct 30, 2025
generally speaking only the outer-most ASGI app runs the lifespan. So in your case,
appin the lifespan is Reflex's outerStarletteapp, not yourFastAPIapp.as a workaround you can probably look through the starlette mounts, find the FastAPI instance, and assign your db to that.
Warn when a transformer's lifespan is also a registered lifespan task
Send ASGI lifespan events to api_transformer apps; drop the extra top…