Jump to solution
Verify

The Fix

pip install fastapi==0.128.4

Based on closed fastapi/fastapi issue #14467 · 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
@@ -171,6 +171,13 @@ def _get_model_config(model: BaseModel) -> Any: +def _has_computed_fields(field: ModelField) -> bool: + computed_fields = field._type_adapter.core_schema.get("schema", {}).get( + "computed_fields", []
repro.py
from fastapi import FastAPI from fastapi.openapi.utils import get_openapi from pydantic import BaseModel, computed_field class ModelWithComputedField(BaseModel): name: str @computed_field @property def computed_name(self) -> str: return f"computed_{self.name}" class SimpleModel(BaseModel): value: str app = FastAPI() @app.get("/with-computed") def route_with_computed() -> ModelWithComputedField: """Route returning a model with computed fields.""" return ModelWithComputedField(name="test") @app.get("/without-computed") def route_without_computed() -> SimpleModel: """Route returning a simple model (no computed fields).""" return SimpleModel(value="test") if __name__ == "__main__": # This will raise KeyError when both routes are present schema = get_openapi( title="Test App", version="1.0.0", routes=app.routes, separate_input_output_schemas=False, # Bug only occurs with False )
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 relies on separate input/output schemas.\n\nOption C — Workaround\nGenerate schemas separately for routes with and without computed fields, then merge them.\nWhen NOT to use: This fix should not be used if the application relies on separate input/output schemas.\n\n

Why This Fix Works in Production

  • Trigger: json_schema = field_mapping[(field, override_mode or field.mode)]
  • Mechanism: The schema generation crashes with a KeyError when mixing routes with and without computed fields
  • Why the fix works: Fixes a bug where the OpenAPI schema generation crashes with a KeyError when mixing routes with and without computed fields. (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.13 in real deployments (not just unit tests).
  • The schema generation crashes with a KeyError when mixing routes with and without computed fields
  • Surfaces as: File "../python3.13/site-packages/fastapi/_compat/v2.py", line 192, in get_schema_from_model_field

Proof / Evidence

Verified Execution

We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.

  • Status: PASS
  • Ran: 2026-02-11T16:52:29Z
  • Package: fastapi
  • Fixed: 0.128.4
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)

Discussion

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

“Fixed by https://github.com/fastapi/fastapi/pull/14453”
@tiangolo · 2025-12-05 · source

Failure Signature (Search String)

  • json_schema = field_mapping[(field, override_mode or field.mode)]

Error Message

Stack trace
error.txt
Error Message ------------- File "../python3.13/site-packages/fastapi/_compat/v2.py", line 192, in get_schema_from_model_field json_schema = field_mapping[(field, override_mode or field.mode)] ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: (ModelField(field_info=FieldInfo(annotation=SimpleModel, required=True), name='Response_route_without_computed_without_computed_get', mode='serialization'), 'validation')

Minimal Reproduction

repro.py
from fastapi import FastAPI from fastapi.openapi.utils import get_openapi from pydantic import BaseModel, computed_field class ModelWithComputedField(BaseModel): name: str @computed_field @property def computed_name(self) -> str: return f"computed_{self.name}" class SimpleModel(BaseModel): value: str app = FastAPI() @app.get("/with-computed") def route_with_computed() -> ModelWithComputedField: """Route returning a model with computed fields.""" return ModelWithComputedField(name="test") @app.get("/without-computed") def route_without_computed() -> SimpleModel: """Route returning a simple model (no computed fields).""" return SimpleModel(value="test") if __name__ == "__main__": # This will raise KeyError when both routes are present schema = get_openapi( title="Test App", version="1.0.0", routes=app.routes, separate_input_output_schemas=False, # Bug only occurs with False )

Environment

  • Python: 3.13

What Broke

OpenAPI schema generation fails, causing application downtime and inability to serve API documentation.

Why It Broke

The schema generation crashes with a KeyError when mixing routes with and without computed fields

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 relies on separate input/output schemas.

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

Option C — Workaround Temporary workaround

Generate schemas separately for routes with and without computed fields, then merge them.

When NOT to use: This fix should not be used if the application relies on separate input/output schemas.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

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

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 relies on separate input/output schemas.

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.