Repository navigation
Conversation
Member
Author
Closing: modern-python/modern-di#602 lets a nullable or defaulted parameter fall back when its context value is unset, so the template's existing |
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.
Refs modern-python/modern-di#579.
Closes #56
Summary
modern-di 4.0 makes context values required.
choose_sa_enginetookrequest: litestar.Request[...] | None = None, filled from the integration's requiredlitestar_request_provider, so resolvingdynamic_engineoutside an HTTP request (tests/test_db_routing.py::test_no_request_uses_primary) raisesContextValueNotSetErroron 4.0.Following the migration guide,
Dependenciesnow declares its ownoptional_request(ContextProvider(litestar.Request, scope=Scope.REQUEST, bound_type=None, default=None)) and passes it todynamic_engineexplicitly.default=onContextProviderexists only in modern-di 4, so this PR needs modern-di 4. It lands together with bumping themodern-di-litestarpin to the release that allows modern-di 4. That release does not exist yet, so the pin is unchanged here.CI on the current pin
CI fails until the pin bump, because
modern-di-litestar>=3,<4resolves modern-di 3.5.0, whoseContextProviderhas nodefaultparameter:tyreportserror[unknown-argument]: Argument `default` does not match any known parameter of `ContextProvider.__init__`atapp/ioc.py:26.app.iocraisesTypeError: ContextProvider.__init__() got an unexpected keyword argument 'default'.Verification
Local, Python 3.14, Postgres 14 in Docker, against the modern-di main wheel (the 4.0 candidate) installed over the synced env and run with
uv run --no-sync: ruff format/check and ty clean, pytest 31 passed, coverage 100%. Before this changetest_no_request_uses_primaryfailed withContextValueNotSetError.Stays draft until modern-di 4.0.0 and a modern-di-litestar release that allows it are on PyPI.