Skip to content

fix(tests): adopt modern-di 3.1 lifecycle, drop deprecated validate= - #8

Merged
lesnik512 merged 1 commit into
mainfrom
fix/modern-di-3.1-lifecycle-and-validate
Jul 28, 2026
Merged

fix(tests): adopt modern-di 3.1 lifecycle, drop deprecated validate=#8
lesnik512 merged 1 commit into
mainfrom
fix/modern-di-3.1-lifecycle-and-validate

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Two changes, both caused by modern-di 3.1 and both needed for this package to be correct against it. 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)

modern-di 3.1 makes a container open from construction — 3.0 built them closed and required an explicit open(). Assertions written against the old contract now fail. These failures predate this PR: they reproduce on main with 3.1.1 installed.

The fix keeps each test's actual subject. Where the assertion was only a precondition, it now states the 3.1 one. Where the subject was the lifecycle transition, the container is closed first so the transition stays observable — otherwise the assertion would pass without the signal doing anything.

2. The documented example uses a deprecated no-op

3.1 also made Container(validate=...) a deprecated no-op that emits ValidateArgumentWarning, moving validation to an explicit container.validate() call:

  • validate=True emits a DeprecationWarning on every construction, from copy-pasted official documentation. A suite following modern-di's own readiness recipe (filterwarnings = ["error::DeprecationWarning"]) fails on it.
  • More quietly: it was the explicit opt-in to graph validation. It now does nothing, so anyone following these docs believes they are validated and is not.

README and examples/ now build the container plain and call container.validate() after setup_di — the ordering the core docs prescribe, since setup_di registers this integration's providers. Where the example built the container inline, it is hoisted so it can be validated at all. Tests drop the argument only.

Historical planning/ files are left untouched. Suite green after both changes. The docs half matches the pattern reviewed in modern-di-fastapi#37.

🤖 Generated with Claude Code

Two changes, both from modern-di 3.1.

Containers are open from construction in 3.1; 3.0 built them closed. Assertions
written against the old contract fail on 3.1.1 - these failures predate this
commit and reproduce on main. Preconditions now state the 3.1 contract; where a
test subject WAS the lifecycle transition, the container is closed first so the
transition stays observable rather than passing vacuously.

Container(validate=...) is also a deprecated no-op now that emits
ValidateArgumentWarning, so README and examples build the container plain and
call container.validate() after setup_di, and tests drop the argument.
@lesnik512
lesnik512 merged commit 0c169e7 into main Jul 28, 2026
6 checks passed
@lesnik512
lesnik512 deleted the fix/modern-di-3.1-lifecycle-and-validate branch July 28, 2026 10:20
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