fix: adopt modern-di 3.1 lifecycle and explicit validation - #8
Merged
Conversation
The suite was already red against 3.1.1 on main: a test expected root.open() to raise ValidationFailedError, but 3.1 validates nowhere implicitly. The ordering rule it guards still exists and now binds validate(), so both siblings are rewritten to that call - validating before setup_di fails because flask_request_provider does not exist yet; after it, succeeds. The README and architecture doc also explained that .open() is required and that validate=True runs at open() time. Neither is true in 3.1: containers are open from construction and open() runs no validation. Docs, example and architecture now build the container plain, drop the unnecessary open(), and validate after setup_di. The caller-owned close_sync() at shutdown is unchanged.
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.
Two changes, both caused by modern-di 3.1. This package pins
modern-di>=3,<4, so users and CI pick 3.1 up on a routine upgrade.1. The suite is already red on 3.1 (fixed here)
test_open_before_setup_di_fails_validation_for_hard_request_dependencyexpectsroot.open()to raiseValidationFailedError. In 3.1open()validates nothing — validation is an explicitcontainer.validate()call — so it does not raise. This failure predates this PR: it reproduces onmainwith 3.1.1 installed.The ordering rule the test guards still exists; it just binds a different call now. Both siblings are rewritten to
validate(), keeping their subject: validating beforesetup_difails, becauseflask_request_providerdoes not exist yet; validating after it succeeds.2. The documented example uses a deprecated no-op, and the prose is wrong
3.1 made
Container(validate=...)a deprecated no-op emittingValidateArgumentWarning. Worse, the README andarchitecture/dependency-injection.mdboth explain that.open()is "required under modern-di 3.x's mandatory-open lifecycle, sincevalidate=Trueruns atopen()time". Neither half is true in 3.1: a container is open from construction, andopen()runs no validation.README,
examples/app.pyandarchitecture/dependency-injection.mdnow build the container plain, drop the unnecessary.open(), and callcontainer.validate()aftersetup_di. The genuinely caller-owned half —close_sync()at shutdown, since Flask has no shutdown hook — is unchanged and still documented.The adapter's own
child.open()in_enter_requestis left as-is; it is a no-op on 3.1 rather than a bug, and removing it is a runtime change that belongs in its own PR. The architecture doc now says so instead of calling it required.Historical
planning/files are untouched. Suite green (12 passed). The docs half matches the pattern reviewed in modern-di-fastapi#37.🤖 Generated with Claude Code