Repository navigation
Fix injection in mounted apps, late routes and stacked subscribers - #330
Merged
Merged
Conversation
Contributor
`install()` now descends into mounted applications, keeps validating routes added after it runs, and the middleware leaves the container in the ASGI scope so a mounted app can reach it. The FastStream extension wires every handler of a subscriber, not just the first. Installing settings twice names the model and the field that collided, and takes `override=True`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
antonrh
force-pushed
the
fix-extensions
branch
from
August 31, 2026 07:46
e929cb1 to
7381caa
Compare
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.
Four bugs the extension review found, each reproduced first.
A mounted sub-application was invisible
_iter_routeswalked included routers but notMount, so a sub-app's routeswere never validated, and
get_containerreadconnection.app.state, whichfor a mounted app is the sub-app's own state that nobody filled:
install()now walks mounted applications and gives each one the container,and the container is looked up in the ASGI scope first, since a mounted app
replaces
scope["app"]with itself. When there is no container anywhere, thefailure says so instead of surfacing a Starlette attribute error.
A route added after
install()failed at request timeinstall()walkedapp.routesonce, so anything registered later reached thehandler unwired and died with
TypeError: Dependency type is not set., namingneither the route nor the parameter.
install()now watchesadd_api_route,add_api_websocket_route,include_routerandmount, so alate route is validated as it is added, with the same message a route present
at install time gets.
Only the first handler of a subscriber was injected
_get_broker_handlersreadsubscriber.calls[0].handler. A subscriberdecorated more than once, the normal way to attach filtered handlers to one
topic, left every handler after the first without an owner, and the failure
appeared only when a message routed to it.
pydantic_settings.install()could not run twiceA second call, which an app factory called per test does, died with
LookupError: The provider Annotated[str, 'settings.name'] is already registered— naming neither the settings class nor the field. It now namesboth, and takes
override=Truefor the case where installing again is thepoint.
Both landing changes are documented: "Mounted applications" on the FastAPI
page and "Installing twice" on the pydantic-settings page.