Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: `predict()` sends request body as raw string, breaks with `pydantic>=2`

未关闭 适合新手
#241 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
fastapi, python
领域
api

调研方向

从 vetiver/server.py 中的 predict() 开始,检查请求体是如何发送到 /predict 端点的。使用提供的 FastAPI TestClient 示例在 pydantic 2 下重现该失败,然后验证 predict() 返回预测结果的 DataFrame,且不会出现 422 响应。

由索引模型根据 Issue 内容生成。

描述

Describe the bug
The predict() function in vetiver/server.py sends DataFrame data using requests.post(endpoint, data=...), which transmits the JSON as a raw byte string without setting Content-Type: application/json.

On the server side, the /predict endpoint declares its input as List[Model], relying on FastAPI + Pydantic to parse the body. Pydantic v1 was lenient enough to coerce the raw bytes into the expected type, but pydantic v2 strictly rejects it with a 422:

"Input should be a valid list".

data= sends the body as raw bytes. It should use json= (or set the content type to application/json) so that FastAPI correctly parses the body before handing it to pydantic for validation.

pydantic: 2.12.5
vetiver: 0.2.6

To Reproduce

import vetiver
from fastapi.testclient import TestClient

X, y = vetiver.mock.get_mock_data()
model = vetiver.mock.get_mock_model().fit(X, y)
v = vetiver.VetiverModel(model=model, model_name="model", prototype_data=X)
app = vetiver.VetiverAPI(v).app

client = TestClient(app)
response = vetiver.predict(
    "http://testserver/predict", X, test_client=client
)
Traceback (most recent call last):
  File "vetiver/server.py", line 379, in predict
    response.raise_for_status()
  File "httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 'http://testserver/predict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo.py", line 11, in <module>
    response = vetiver.predict(
        "http://testserver/predict", X, test_client=client
    )
  File "vetiver/server.py", line 382, in predict
    raise TypeError(re.sub(r"\n", ": ", response.text))
TypeError: 1 validation error::   {'type': 'list_type', 'loc': ('body',), 'msg': 'Input should be a valid list', 'input':
b'[{"B":54,"C":48,"D":68},...]'}: :   File "vetiver/server.py", line 238, in custom_endpoint:     POST /predict

Expected behavior
vetiver.predict() should return a DataFrame of predictions. With pydantic<2 installed, it does

Additional context
Add any other context about the problem here.

主要语言
Python
星标
71
派生
20
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rstudio/vetiver-python 的其他 Issue

查看 rstudio/vetiver-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。