-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Ensure that app.include_router
merges nested lifespans
#9630
Conversation
📝 Docs preview for commit 860c851 at: https://647f7cdb633e285f9b5dace9--fastapi.netlify.app |
app.include_router
doesn't nest lifespansapp.include_router
doesn't merge nested lifespans
📝 Docs preview for commit 984e59f at: https://647f7f0b29b2f764bcaa3dd9--fastapi.netlify.app |
📝 Docs preview for commit 8f26ed5 at: https://6484cca7bf187a105b276a5e--fastapi.netlify.app |
@tiangolo can you take a look here, please? It's a minor bugfix, but it's important for my project. |
app.include_router
doesn't merge nested lifespansapp.include_router
doesn't merge nested lifespans
📝 Docs preview for commit f322c99 at: https://648c2ec07c8ac9541405829c--fastapi.netlify.app |
📝 Docs preview for commit 3e2fd98 at: https://648e16b538df29410a152328--fastapi.netlify.app |
This is not minor, and ideally we'd like this to live in Starlette. |
@Kludex maybe, but how we can move it to Starlette if |
This will require a lot of work in both FastAPI and Starlette, since none of the FastAPI methods uses |
@Kludex this bug doesn't on Starlette side and not connected with this Issue or this Starlette PR or Issue. It should be fixed in FastAPI cuz we have no Starlette calls inside So can you review and approve this PR? |
Starlette should support running the lifespan of other routers... It shouldn't be here. |
But there no other routers. We have the original @Kludex just take a look at FastAPI original code here A FastAPI application works with an only one original router (if we didn't use |
+1 |
1 similar comment
+1 |
+1) |
+1 |
Wait for fix |
+1 |
1 similar comment
+1 |
@tiangolo can we have a minute of your time here? |
I am sorry to annoy you, but it is 14 months since PR is opened. Can we, as a community, have a decision or plan? |
@svlandeg @estebanx64 @alejsdev Hello, team! Sorry for such annoyiment, but we are still waiting for any decision about this PR. FastAPI now has an obvious bug / weaknesses. And we have the PR fixing it. I know, that this thing should be fixed in the future according to Roadmap, but we are waiting year already for it. Have we any reason to not merge 10 lines of code if they fixing the problem already and we can remove them in the future as a part of Roamap feature scope? |
+1 |
3 similar comments
+1 |
+1 |
+1 |
|
+1 |
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
app.include_router
doesn't merge nested lifespansapp.include_router
merges nested lifespans
Thank you for your contribution @Lancetnik! 🍰 Thanks everyone for the input. ☕ Thanks a lot for the help, as always, @Kludex 🙏 🙇 This will be available in FastAPI version Thanks everyone for the patience. As this involved some internal changes, that means there's a bit of a higher chance it could break something else elsewhere (something we didn't expect and didn't account for), so I wanted to handle some other lower-impact issues and releases first. Now I was finally able to sit a few hours dedicated just to this, read several parts of the ASGI spec again, ensure this would be the right way to handle things (e.g. what nested lifespan states should override which), etc. Now, time to enjoy your new nested lifespans. 😎 ☕ |
I am working on my own Propan library and as a part of it I implemented a custom FastAPI router with the following behavior.
To connect RabbitMQ at FastAPI startup I used
router.on_startup
events and all worked fine, but now it is deprecated. So I migrate tolifespan
and now FastAPI doesn't run router lifespan at the code above.I suppose it was missed cuz the original
include_router
method includes all nestedon_startup
andon_shutdown
deprecated events here, but doesn't includes a router lifespan.So, the following code doesn't work
The current PR fixes the original framework miss.
All original test and lint.sh checks works fine.