python
data_error
ai_generated
true
fastapi.exceptions.RequestValidationError: 1 validation error for Request query -> q field required (type=value_error.missing)
ID: python/fastapi-422-missing-query-param
80%Fix Rate
86%Confidence
0Evidence
2024-03-29First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A function parameter declared without a default is treated as a required query parameter and the client omitted it.
generic中文
未声明默认值的函数参数被视为必填查询参数,而客户端省略了它。
Workarounds
-
95% success
from fastapi import Query @app.get('/search') async def search(q: str = Query(default='')): ... -
92% success
async def search(q: str | None = None): ...
Dead Ends
Common approaches that don't work:
-
85% fail
Still required; Query(...) means required.
-
70% fail
Hides the contract mismatch from the client.