fix: open request child container for modern-di 3.x mandatory-open#6
Merged
Conversation
…open) Under modern-di 3.0's mandatory-open lifecycle, resolving from an unopened container raises ContainerClosedError. inject's per-task wrapper built a Scope.REQUEST child container and resolved from it without opening it; wrap it in a sync `with` instead (Container.__enter__ opens, __exit__ closes), dropping the manual try/finally. Also opens the root APP container in the test fixture / bespoke test app: Celery's worker_process_init signal (which opens it in production) never fires under task_always_eager, so tests were masking the bug at the parent container instead of exercising the real per-task path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings
modern-di-celeryonto modern-di 3.x. Part of the 12-package wave; mirrorsmodern-di-litestar3.0.0.modern-dito>=3,<4(drops 2.x support).inject's per-task wrapper built aScope.REQUESTchild container and resolved from it without opening it, so every@inject-wrapped task call raisedContainerClosedError. Now the wrapper enters the child container via a syncwith(Container.__enter__opens,__exit__closes), preserving the same close-on-error teardown as before.tests/conftest.py'sappfixture (and one bespoke test app) now opens the root container explicitly, since Celery'sworker_process_initsignal — which opens it in production — never fires undertask_always_eager.Planning:
planning/changes/2026-07-20.01-open-request-child-container.md, release notes inplanning/releases/3.0.0.md.🤖 Generated with Claude Code