The Fix
Upgrade to version 0.23.1 or later.
Based on closed Kludex/starlette issue #1977 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -89,8 +89,6 @@ async def body_stream() -> typing.AsyncGenerator[bytes, None]:
if body:
yield body
- if not message.get("more_body", False):
- break
import uvicorn
from fastapi import FastAPI
from starlette.middleware.base import BaseHTTPMiddleware
app = FastAPI()
@app.get("/info")
def info():
# raises Exception as expected, the traceback is seen in console
raise Exception
private_api = FastAPI()
@private_api.get("/info")
def info():
# exception is handled silently, no traceback is seen in console
raise Exception
app.mount("/private", private_api)
class Middleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
return await call_next(request)
app.add_middleware(Middleware) # when this is removed, the exceptions are raised for all routes
if __name__ == '__main__':
uvicorn.run(app, port=8000)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.23.1 or later.\nWhen NOT to use: Do not use this fix if middleware behavior is expected to suppress exceptions intentionally.\n\n
Why This Fix Works in Production
- Trigger: middleware causes exceptions to not be raised/handled silently
- Mechanism: Exceptions raised on subapps were not propagated correctly due to middleware handling
- Why the fix works: Resolves the issue where exceptions raised on a subapp are not propagated correctly when using middleware. (first fixed release: 0.23.1).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Exceptions raised on subapps were not propagated correctly due to middleware handling
- Production symptom (often without a traceback): middleware causes exceptions to not be raised/handled silently
Proof / Evidence
- GitHub issue: #1977
- Fix PR: https://github.com/kludex/starlette/pull/1940
- First fixed release: 0.23.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.49
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Probably introduced by https://github.com/encode/starlette/pull/1715, if not... Maybe https://github.com/encode/starlette/pull/1649? cc @adriangb”
“It was none of those PRs. This was cased by https://github.com/encode/starlette/pull/1609. Solution on #1940.”
“I'm experiencing this issue as well since the upgrade to starlette >= 0.28”
Failure Signature (Search String)
- middleware causes exceptions to not be raised/handled silently
- When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console
Copy-friendly signature
Failure Signature
-----------------
middleware causes exceptions to not be raised/handled silently
When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console
Error Message
Signature-only (no traceback captured)
Error Message
-------------
middleware causes exceptions to not be raised/handled silently
When exceptions are raised on a subapp, the exceptions are not propagated all the way to see in console
Minimal Reproduction
import uvicorn
from fastapi import FastAPI
from starlette.middleware.base import BaseHTTPMiddleware
app = FastAPI()
@app.get("/info")
def info():
# raises Exception as expected, the traceback is seen in console
raise Exception
private_api = FastAPI()
@private_api.get("/info")
def info():
# exception is handled silently, no traceback is seen in console
raise Exception
app.mount("/private", private_api)
class Middleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
return await call_next(request)
app.add_middleware(Middleware) # when this is removed, the exceptions are raised for all routes
if __name__ == '__main__':
uvicorn.run(app, port=8000)
What Broke
Exceptions in subapps fail silently, leading to missing stack traces in logs.
Why It Broke
Exceptions raised on subapps were not propagated correctly due to middleware handling
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.23.1 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/kludex/starlette/pull/1940
First fixed release: 0.23.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if middleware behavior is expected to suppress exceptions intentionally.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.23.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.