python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: 1 validation error for ItemCreate body -> name field required (type=value_error.missing)
ID: python/fastapi-422-field-required-body
80%Fix Rate
90%Confidence
0Evidence
2024-02-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
Root Cause
Client sent a JSON body missing a field that the Pydantic model declares as required (no default).
generic中文
客户端发送的 JSON 请求体缺少 Pydantic 模型声明为必需(无默认值)的字段。
Workarounds
-
92% success
from typing import Optional class ItemCreate(BaseModel): name: Optional[str] = None -
95% success
requests.post(url, json={'name': 'x', 'price': 1.0}) # include all required fields
Dead Ends
Common approaches that don't work:
-
95% fail
Response model affects serialization, not request validation.
-
80% fail
Validation runs before your middleware can bypass it; also disables all validation.