bug: `predict()` sends request body as raw string, breaks with `pydantic>=2`
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
調査の方向性
vetiver/server.py の predict() から始め、リクエストボディが /predict エンドポイントにどのように送信されるかを調べます。pydantic 2 環境で、提供されている FastAPI TestClient の例を使って失敗を再現し、その後、predict() が 422 レスポンスなしで予測の DataFrame を返すことを確認します。
索引モデルが 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rstudio/vetiver-python のほかの issue
-
bug deploy pins
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
rstudio/vetiver-python#240 · コメント 2 件 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
rstudio/vetiver-python#239 · コメント 2 件 ·
-
deploy enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
rstudio/vetiver-python#238 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
rstudio/vetiver-python#237 · リアクション 1 件 ·
-
connect
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
rstudio/vetiver-python#236 · リアクション 1 件 ·
rstudio/vetiver-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
spec-kitty/spec-kitty#6112 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: OpenRouter streaming chunks report the requested router name instead of the model OpenRouter served対応中かも @Mrun25 が今日担当しました。 オープンbug llm translation
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
BerriAI/litellm#46095 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
uberdeveloper/fastbt#29 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
andrew-blake/melcloudhome#368 ·
メンテナーはふだん 1 日以内に返信
-
lane:discover
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SPARDiffData/differential-data-collection#33 ·
メンテナーはふだん 1 日以内に返信