python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: path -> id value is not a valid uuid (type=type_error.uuid)
ID: python/fastapi-path-param-422-uuid
80%Fix Rate
86%Confidence
0Evidence
2024-07-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The path parameter is declared as UUID but the URL segment is not a valid UUID string.
generic中文
路径参数声明为 UUID,但 URL 片段不是有效的 UUID 字符串。
Workarounds
-
90% success
@app.get('/items/{item_id}') def get(item_id: str): try: uid = UUID(item_id) except ValueError: raise HTTPException(400) -
88% success
from fastapi import Path def get(item_id: UUID = Path(...)): ...
Dead Ends
Common approaches that don't work:
-
75% fail
Still fails if the regex matches but the value is not a UUID.
-
90% fail
Validation runs before the handler; except never triggers.