-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Sharing cleanup_ctx data with sub-apps #3876
Comments
I ask mostly to know if there is a planned design for that, as there are a few options:
Item 1 seems the most likely to be a good approach, and then nested apps could have their signal check for a resource or create their own to make it more pluggable. |
Do you have an idea of how the usage code should look like? |
Faced the same issue. I want to initialise db variable in main app in |
I ended up deciding that a parent app knowing about subapps is 100% ok, so for one app we are just explicity setting the properties on a subapp. With testing they are easy enough to set by just testing the nested apps on their own merit. Here's a sample from ours (option #1 above): async def postgresql_pool(app: web.Application) -> AsyncGenerator[None, None]:
async with asyncpg.create_pool(dsn=app["POSTGRESQL_DSN"]) as pool:
app["db"] = app["website_app"]["db"] = pool
yield Where There may be merit in just having a last-signal register them all ( |
There is a documented approach of sharing resources from parent apps to nested apps in #2413. However that does not work for the common case of using CleanupContext managed resources (such as a database or redis pool).
Is there a recommended way of sharing resources provided by a root application's context signals?
Originally posted in #2412 (comment)
The text was updated successfully, but these errors were encountered: