python data_error ai_generated true

fastapi.exceptions.RequestValidationError: 422 - query parameter 'page' must be greater than or equal to 1

ID: python/fastapi-query-param-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-02-25First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

查询参数不符合定义的约束条件,如最小值为 1。

generic

中文

查询参数不符合定义的约束条件,如最小值为 1。

Workarounds

  1. 95% success
    使用 Query(ge=1) 定义参数约束。
  2. 90% success
    添加全局验证错误处理器返回清晰消息。
  3. 85% success
    在客户端和服务器端都进行验证。

Dead Ends

Common approaches that don't work:

  1. 80% fail

    忽略错误,不检查参数值。

  2. 60% fail

    尝试在前端限制,但后端仍不验证。

  3. 70% fail

    修改约束但忘记更新文档。