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
Bugfix: app.include_router
doesn't merge nested lifespans
#9630
base: master
Are you sure you want to change the base?
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 |
Would love the functionality to get restored/implemented, recently upgraded fastapi code that previously made use of @router.on_event("startup") inside a router object. But the switch to lifespan has broken this functionality, when the router is included into a FastAPI() object. I don't know the codebase well enough, but is the FastAPI object+ router object 's lifespan code part of Starlette? |
@neeps yes, lifespan functional is a part of Starlette, but |
Thank you for clarifying, I've downgraded to pre-lifespan for the time being. |
@Kludex sorry for being annoying. I know, that
Is in roadmap and It will fix the problem But why we can't merge this PR for now? It just a few lines of code and it fixes the problem already without any waiting for abstract "roadmap". Working solution is better than perfect, but in the future, isn't it? |
If we can't fix this now, would you accept a PR to raise a |
Any updates on this PR? Is it going to be merged? |
Any updates on this PR? @tiangolo |
Hi, I'm trying to use lifespan with ApiRouter() instead of FastApi instance. It is still not working. Can you pin the latest stable version where the startup/shutdown was functional. |
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 Fast API startup I used
router.on_startup
events and all worked fine, but now it is deprecated. So I migrate tolifespan
and now Fast API 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.