# fastapi.exceptions.RequestValidationError: Request 的 1 个校验错误
query -> q
  字段缺失 (type=value_error.missing)

- **ID:** `python/fastapi-422-missing-query-param`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

未声明默认值的函数参数被视为必填查询参数，而客户端省略了它。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   from fastapi import Query
@app.get('/search')
async def search(q: str = Query(default='')):
    ...
   ```
2. **** (92% 成功率)
   ```
   async def search(q: str | None = None):
    ...
   ```

## 无效尝试

- **** — Still required; Query(...) means required. (85% 失败率)
- **** — Hides the contract mismatch from the client. (70% 失败率)
