Jump to solution
Verify

The Fix

Upgrade to version 0.19.0 or later.

Based on closed Kludex/starlette issue #1433 · 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%.

Jump to Verify Open PR/Commit
@@ -52,6 +52,9 @@ async def body_stream() -> typing.AsyncGenerator[bytes, None]: yield message.get("body", b"") + if app_exc is not None: + raise app_exc +
repro.py
import httpx import pytest from fastapi import FastAPI, APIRouter from starlette.middleware import Middleware from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint from starlette.requests import Request from starlette.responses import Response from starlette.routing import Route class SomeError(Exception): pass class SomeMiddleware(BaseHTTPMiddleware): async def dispatch( self, request: Request, call_next: RequestResponseEndpoint ) -> Response: return await call_next(request) # Drop (or use not BaseHTTPMiddleware based) middleware and test works fine app = FastAPI(middleware=[Middleware(SomeMiddleware), ]) async def simple_route(request: Request): raise SomeError another_router = APIRouter( routes=[Route('/simple-route/', simple_route, methods=['GET'])] ) sub_app = FastAPI() sub_app.include_router(another_router) app.router.mount(f'/api', sub_app) @pytest.mark.asyncio async def test_simple_route(): async with httpx.AsyncClient(app=app) as client: with pytest.raises(SomeError): await client.get("http://testserver/api/simple-route/")
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 0.19.0 or later.\nWhen NOT to use: Do not use this fix if your application relies on the previous behavior of suppressing exceptions.\n\n

Why This Fix Works in Production

  • Trigger: Raising Exceptions in sub-applications routes
  • Mechanism: BaseHTTPMiddleware does not correctly raise exceptions from StreamingResponse in sub-applications
  • Why the fix works: Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse, ensuring exceptions are raised correctly in sub-applications. (first fixed release: 0.19.0).
Production impact:
  • 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

  • Shows up under Python 3.9.9 in real deployments (not just unit tests).
  • BaseHTTPMiddleware does not correctly raise exceptions from StreamingResponse in sub-applications
  • Production symptom (often without a traceback): Raising Exceptions in sub-applications routes

Proof / Evidence

  • GitHub issue: #1433
  • Fix PR: https://github.com/kludex/starlette/pull/1459
  • First fixed release: 0.19.0
  • 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.43

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“### Checklist - [X] The bug is reproducible against the latest release or master. - [X] There are no similar issues or pull requests to fix it yet. ### Describe the bug Let's start with this PR: #1262 It's about preventing raise anyio.Excep”
Issue thread · issue description · source

Failure Signature (Search String)

  • Raising Exceptions in sub-applications routes
  • It's about preventing raise `anyio.ExceptionGroup` in views under a `BaseHTTPMiddleware`. PR resolve that problem with nonlocal variable that stores our exception. But in the case
Copy-friendly signature
signature.txt
Failure Signature ----------------- Raising Exceptions in sub-applications routes It's about preventing raise `anyio.ExceptionGroup` in views under a `BaseHTTPMiddleware`. PR resolve that problem with nonlocal variable that stores our exception. But in the case of sub-applications, it does not work.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Raising Exceptions in sub-applications routes It's about preventing raise `anyio.ExceptionGroup` in views under a `BaseHTTPMiddleware`. PR resolve that problem with nonlocal variable that stores our exception. But in the case of sub-applications, it does not work.

Minimal Reproduction

repro.py
import httpx import pytest from fastapi import FastAPI, APIRouter from starlette.middleware import Middleware from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint from starlette.requests import Request from starlette.responses import Response from starlette.routing import Route class SomeError(Exception): pass class SomeMiddleware(BaseHTTPMiddleware): async def dispatch( self, request: Request, call_next: RequestResponseEndpoint ) -> Response: return await call_next(request) # Drop (or use not BaseHTTPMiddleware based) middleware and test works fine app = FastAPI(middleware=[Middleware(SomeMiddleware), ]) async def simple_route(request: Request): raise SomeError another_router = APIRouter( routes=[Route('/simple-route/', simple_route, methods=['GET'])] ) sub_app = FastAPI() sub_app.include_router(another_router) app.router.mount(f'/api', sub_app) @pytest.mark.asyncio async def test_simple_route(): async with httpx.AsyncClient(app=app) as client: with pytest.raises(SomeError): await client.get("http://testserver/api/simple-route/")

Environment

  • Python: 3.9.9

What Broke

Exceptions raised in sub-application routes are not propagated, leading to silent failures.

Why It Broke

BaseHTTPMiddleware does not correctly raise exceptions from StreamingResponse in sub-applications

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 0.19.0 or later.

When NOT to use: Do not use this fix if your application relies on the previous behavior of suppressing exceptions.

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/1459

First fixed release: 0.19.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if your application relies on the previous behavior of suppressing exceptions.

Verify Fix

verify
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

VersionStatus
0.19.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.