fix: use lifespan context manager in Starlette and FastAPI - #368
Conversation
|
Closes #367 |
|
@cofin If you don't mind me adding, the changes you made to AdvancedAlchemy seem like it would run each config's on_startup/on_shutdown twice if the user does not define a custom lifespan, but only once if the user does define lifespan. That's probably fine for create_all and engine.dispose, but maybe the add_event_handler functions in the config classes should be removed if this isn't intended? Also the outer shutdown doesn't run when hit with an exception 😅 |
Hah. Is it obvious I don't use FastAPI daily? :) |
Your suggestions were spot on. I think I've finally addressed all of the issues on this one. Thanks again. |
e0b10aa to
eb00469
Compare
|
|
Documentation preview will be available shortly at https://litestar-org.github.io/advanced-alchemy-docs-preview/368 |
|
Thank you! |



Modifes the Starlette and FastAPI integrations to use the
lifespancontext manager instead of thestartup`shutdown` hooks. If the application already has a lifespan set, it is wrapped so that both execute.