The Fix
pip install fastapi==0.128.4
Based on closed fastapi/fastapi issue #14483 · 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%.
@@ -1,7 +1,7 @@
import warnings
from copy import copy, deepcopy
-from dataclasses import dataclass
+from dataclasses import dataclass, is_dataclass
from enum import Enum
from typing import Annotated
import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel, ConfigDict, WithJsonSchema, TypeAdapter
type MyNumpyArray = Annotated[
np.ndarray, WithJsonSchema(TypeAdapter(list[float]).json_schema(), mode="serialization"),
]
class MyModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
custom_field: MyNumpyArray
app = FastAPI()
@app.get("/")
def test() -> MyModel:
raise NotImplementedError()
print(app.openapi())
# {'openapi': '3.1.0', 'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'paths': {'/': {'get': {'summary': 'Test', 'operationId': 'test__get', 'responses': {'200': {'description': 'Successful Response', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/MyModel'}}}}}}}}, 'components': {'schemas': {'MyModel': {'properties': {'custom_field': {'$ref': '#/components/schemas/MyNumpyArray'}}, 'type': 'object', 'required': ['custom_field'], 'title': 'MyModel'}, 'MyNumpyArray': {'items': {'type': 'number'}, 'type': 'array'}}}}
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install fastapi==0.128.4\nWhen NOT to use: Do not use this fix if arbitrary_types_allowed is not required.\n\n
Why This Fix Works in Production
- Trigger: Since FastAPI 0.119.0, using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI
- Mechanism: Using arbitrary_types_allowed=True with custom types breaks OpenAPI generation
- Why the fix works: Fix handling arbitrary types when using `arbitrary_types_allowed=True` to prevent issues with OpenAPI generation. (first fixed release: 0.128.4).
- 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
- Using arbitrary_types_allowed=True with custom types breaks OpenAPI generation
- Production symptom (often without a traceback): Since FastAPI 0.119.0, using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI
Proof / Evidence
- GitHub issue: #14483
- Fix PR: https://github.com/fastapi/fastapi/pull/14482
- First fixed release: 0.128.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-08
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.41
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“It should be fixed in https://github.com/fastapi/fastapi/pull/14482, available in FastAPI 0.124.1, just released. :tada:”
Failure Signature (Search String)
- Since FastAPI 0.119.0, using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI
- Using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI.
Copy-friendly signature
Failure Signature
-----------------
Since FastAPI 0.119.0, using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI
Using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Since FastAPI 0.119.0, using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI
Using `arbitrary_types_allowed=True` with custom types that define their serialization and JSON Schema breaks when generating OpenAPI.
Minimal Reproduction
from typing import Annotated
import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel, ConfigDict, WithJsonSchema, TypeAdapter
type MyNumpyArray = Annotated[
np.ndarray, WithJsonSchema(TypeAdapter(list[float]).json_schema(), mode="serialization"),
]
class MyModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
custom_field: MyNumpyArray
app = FastAPI()
@app.get("/")
def test() -> MyModel:
raise NotImplementedError()
print(app.openapi())
# {'openapi': '3.1.0', 'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'paths': {'/': {'get': {'summary': 'Test', 'operationId': 'test__get', 'responses': {'200': {'description': 'Successful Response', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/MyModel'}}}}}}}}, 'components': {'schemas': {'MyModel': {'properties': {'custom_field': {'$ref': '#/components/schemas/MyNumpyArray'}}, 'type': 'object', 'required': ['custom_field'], 'title': 'MyModel'}, 'MyNumpyArray': {'items': {'type': 'number'}, 'type': 'array'}}}}
Why It Broke
Using arbitrary_types_allowed=True with custom types breaks OpenAPI generation
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install fastapi==0.128.4
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/14482
First fixed release: 0.128.4
Last verified: 2026-02-08. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if arbitrary_types_allowed is not required.
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.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.