✨ Add support for lifespan async context managers (superseding startup and shutdown events)#2944
Conversation
|
📝 Docs preview for commit 8c33c94 at: https://604c4976cfdb60814a49803c--fastapi.netlify.app |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2944 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 540 243 -297
Lines 13969 7441 -6528
===========================================
- Hits 13969 7441 -6528
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
📝 Docs preview for commit 12e924d at: https://604c4d9c53c6988fd2efed45--fastapi.netlify.app |
|
Hi, we really need this fix, can i help with PR? There is a conflict @uSpike |
|
I rebased, dealt with the commit conflicts and updated a test in #4147 |
|
One of the tests that was added was failing due to a starlette update. Saw that nothing had happened in the last 15 days, and was hoping to lend a hand. I'd also like to see this get implemented, as it's much nicer than referencing the global |
generator lifespans were deprectated in starlette 0.16.0 https://github.com/encode/starlette/releases/tag/0.16.0
|
I've fixed typing, formatting, and updated the docs to communicate that |
|
@tiangolo this seems like a straight forward PR, please have a look if you can, would be great!! |
generator lifespans were deprectated in starlette 0.16.0 https://github.com/encode/starlette/releases/tag/0.16.0
|
📝 Docs preview for commit 5ae6547 at: https://64062412c1f3f7106eff7bd8--fastapi.netlify.app |
|
📝 Docs preview for commit 8b6dd1a at: https://640626d9f5524310c7db8154--fastapi.netlify.app |
lifespan async context managers (superseding startup and shutdown events)
|
Thank you @uSpike! 🙇 🍰 I updated the docs to include more info and make this the recommended way from now on. I also took the updates in #5503, thanks @JonathanPlasse ! ☕ And I added tests for the new example in the docs. This will be available in FastAPI
|
…rtup` and `shutdown` events) (fastapi#2944) Co-authored-by: Mike Shantz <[email protected]> Co-authored-by: Jonathan Plasse <[email protected]> Co-authored-by: Sebastián Ramírez <[email protected]>
This adds support for the
lifespanargument to the application and router, which was added in starlette.I tidied up some of the event tests as well to promote reuse.
Fixes #2943