Skip to content

fix: open request child container for modern-di 3.x mandatory-open#6

Merged
lesnik512 merged 3 commits into
mainfrom
chore/modern-di-3x
Jul 20, 2026
Merged

fix: open request child container for modern-di 3.x mandatory-open#6
lesnik512 merged 3 commits into
mainfrom
chore/modern-di-3x

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Brings modern-di-celery onto modern-di 3.x. Part of the 12-package wave; mirrors modern-di-litestar 3.0.0.

  • Bumps modern-di to >=3,<4 (drops 2.x support).
  • Fixes an adapter bug exposed by 3.0's mandatory-open lifecycle: inject's per-task wrapper built a Scope.REQUEST child container and resolved from it without opening it, so every @inject-wrapped task call raised ContainerClosedError. Now the wrapper enters the child container via a sync with (Container.__enter__ opens, __exit__ closes), preserving the same close-on-error teardown as before.
  • Test-only fix: tests/conftest.py's app fixture (and one bespoke test app) now opens the root container explicitly, since Celery's worker_process_init signal — which opens it in production — never fires under task_always_eager.

Planning: planning/changes/2026-07-20.01-open-request-child-container.md, release notes in planning/releases/3.0.0.md.

🤖 Generated with Claude Code

…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.
@lesnik512
lesnik512 merged commit 695e880 into main Jul 20, 2026
6 checks passed
@lesnik512
lesnik512 deleted the chore/modern-di-3x branch July 20, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant