【发布时间】:2021-12-09 12:22:38
【问题描述】:
在快速 api 中使用正则表达式路径约束时出现错误。
ValueError: On field "serial" the following field constraints are set but not enforced: regex.
For more details see https://pydantic-docs.helpmanual.io/usage/schema/#unenforced-field-constraints
函数签名如下所示。
@devices.get("/{serial}", response_model=Device)
async def get_serial(serial: int = Path(..., regex=r"(?:\d{18}|\d{24})")) -> dict:
错误将我指向 pydantic 文档,但我不明白出了什么问题。我相信他们所建议的正是 fastapi 应该在幕后做的事情。
https://pydantic-docs.helpmanual.io/usage/schema/#unenforced-field-constraints
【问题讨论】: