Jump to solution
Verify

The Fix

pip install fastapi==0.128.4

Based on closed fastapi/fastapi issue #13022 · 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
@@ -1,7 +1,7 @@ from typing import AsyncGenerator, ContextManager, TypeVar -import anyio +import anyio.to_thread from anyio import CapacityLimiter
repro.py
import uvicorn from fastapi import FastAPI, Depends app = FastAPI() def get_something_sync(): yield True async def get_something_async(): yield True @app.get('/1') def router_func(dependency=Depends(get_something_sync)): raise ValueError return @app.get('/2') def router_func(dependency=Depends(get_something_async)): raise ValueError return if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=5600, workers=1)
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\npip install fastapi==0.128.4\nWhen NOT to use: This fix should not be used if the application does not utilize synchronous dependencies with yield.\n\n

Why This Fix Works in Production

  • Mechanism: The traceback is lost when an exception is raised in a synchronous dependency using yield
  • Why the fix works: Preserves the traceback when an exception is raised in a synchronous dependency using yield, addressing the issue of lost traceback information. (first fixed release: 0.128.4).
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.11 in real deployments (not just unit tests).
  • The traceback is lost when an exception is raised in a synchronous dependency using yield
  • Surfaces as: Traceback stack does not show exact place of error

Proof / Evidence

  • GitHub issue: #13022
  • Fix PR: https://github.com/fastapi/fastapi/pull/5823
  • First fixed release: 0.128.4
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-08
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.65

Discussion

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

“I've simplified a bit the PR that solves this: https://github.com/fastapi/fastapi/pull/5823”
@Kludex · 2024-12-02 · source
“I think the issue is not what it's described here, but I'll not spam another one to not create confusion. The issue is actually this…”
@Kludex · 2024-12-02 · source

Failure Signature (Search String)

  • Traceback stack does not show exact place of error

Error Message

Stack trace
error.txt
Error Message ------------- Traceback stack does not show exact place of error

Minimal Reproduction

repro.py
import uvicorn from fastapi import FastAPI, Depends app = FastAPI() def get_something_sync(): yield True async def get_something_async(): yield True @app.get('/1') def router_func(dependency=Depends(get_something_sync)): raise ValueError return @app.get('/2') def router_func(dependency=Depends(get_something_async)): raise ValueError return if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=5600, workers=1)

Environment

  • Python: 3.11

What Broke

Endpoints fail to provide accurate traceback information, leading to confusion during debugging.

Why It Broke

The traceback is lost when an exception is raised in a synchronous dependency using yield

Fix Options (Details)

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

pip install fastapi==0.128.4

When NOT to use: This fix should not be used if the application does not utilize synchronous dependencies with yield.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/fastapi/fastapi/pull/5823

First fixed release: 0.128.4

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the application does not utilize synchronous dependencies with yield.

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.128.4 Fixed

Related Issues

No related fixes found.

Sources

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