bug: `predict()` sends request body as raw string, breaks with `pydantic>=2`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 62/100
Hướng nghiên cứu
Bắt đầu trong vetiver/server.py tại predict() và kiểm tra cách phần thân của request được gửi đến endpoint /predict. Tái hiện lỗi bằng ví dụ FastAPI TestClient được cung cấp trên pydantic 2, sau đó xác minh rằng predict() trả về một DataFrame các dự đoán mà không có phản hồi 422.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 71
- Fork
- 20
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rstudio/vetiver-python
-
bug deploy pins
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
rstudio/vetiver-python#240 · 2 bình luận ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rstudio/vetiver-python#239 · 2 bình luận ·
-
deploy enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
rstudio/vetiver-python#238 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rstudio/vetiver-python#237 · 1 reaction ·
-
connect
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
rstudio/vetiver-python#236 · 1 reaction ·
Tất cả issue của rstudio/vetiver-python
Issue tương tự
-
changelog investigate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ramnes/notion-sdk-py#409 ·
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
lindicaphxag-tech/kaggle#28 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
BSData/horus-heresy-3rd-edition#3211 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày