Pass inner app results through the middleware#2
Merged
Conversation
StaticRewriteMiddleware.__call__ now uses `return await self.app()` on both code paths. Frameworks like Starlette, FastAPI, and Air rely on return values propagating through the middleware stack when using app.add_middleware(). A bare `await` without `return` silently discards the result. Co-authored-by: Daniel Roy Greenfeld <pydanny@users.noreply.github.com>
The ASGI spec is silent on return type, but Starlette and other frameworks define ASGIApp as Awaitable[Any] because middleware chains propagate return values via `return await self.app(...)`. Widening from Awaitable[None] lets ty accept inner apps that return non-None values, which is what the return-value propagation tests exercise. Also applies ruff formatting (import ordering, dict literal style) to both files.
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.
Summary
StaticRewriteMiddleware.call used bare
await self.app()on bothcode paths, which silently discards whatever the inner app returns.
Correct ASGI middleware uses
return await self.app()so the resultpropagates through the chain. This matters for both wiring patterns:
app = StaticRewriteMiddleware(app, static=static)(raw ASGI)app.add_middleware(StaticRewriteMiddleware, static=static)(Starlette / FastAPI / Air)Relates to #1.
Test plan
the HTTP and non-HTTP code paths