-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add container inheritance #146
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
base: main
Are you sure you want to change the base?
Conversation
We can't just ask the parent for the value, since that'll just cause the parent to instantiate it. Instead, Container has to directly walk its ancestors and do the work itself.
|
This is me attempting to upstream some forkish work (ie, making it less of a fork). I'm assuming that people are going to have Opinions:tm: about this. |
|
I'm up to my ears in trying to get structlog out, but could you outline how your approach is supposed to work so I don't have to deduce it from the code? :) |
|
Ok, so The thought is that containers are meant to match the various lifecycles of a complex app. eg, a complex FastAPI app has the overall app, request contexts, spawned tasks, queued jobs, etc. In particular, FastAPI has tasks that spawn from a request (and presumably should inherit the context and therefore the container). The implemented behavior:
Additionally, an inheritable flag is implemented. This is meant to be used to prevent eg database transactions from spanning contexts. I'm not convinced I got the semmantics exactly right, though.
|
|
This above explanation glosses over a subtlety that i think produces a warty behavior. Non-inheritable services still close when the container closes--when all children are unused and close. This is significantly later than before, which can cause problems if you depend on when services close. For example, you have the current database transaction in a FastAPI app making use of spawned tasks. You largely want the spawned task to inherit the context--the request that triggered it, the current user, external services, etc. But you might want a fresh transaction. The trick here is that with the naive implementation, the request's direct transaction won't commit until the spawned task is done. I think most people would consider this an undesirable behavior. This feels a little bit cursed. I want to keep the model as simple as possible, but the only solutions I can think of involve more complexity. Some examples:
|
Summary
Adds the ability for containers to have sub-containers. (Previously floated as #70.)
Pull Request Check List
mainbranch – use a separate branch!docs/core-concepts.mdor one of the integration guides by hand.versionadded,versionchanged, ordeprecateddirectives..rstand.mdfiles is written using semantic newlines.