GetBatchResponseById panics for items without a body (204/302) and for unknown ids
Đá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
- 72/100
Hướng nghiên cứu
Bắt đầu trong batch_requests.go tại GetBatchResponseById; hai điểm lỗi là result.(T) không được kiểm tra sau parseNode.GetObjectValue và resp.GetResponseById không được bảo vệ trước *item.GetStatus(). Tái sử dụng các fixture và helper trong batch_request_test.go — getDummyJSON() đã chứa các item 302 ("1") và 204 ("4") với "body": null — để thêm ba trường hợp từ báo cáo. Hoàn thành nghĩa là body nil trả về T zero mà không có lỗi, một id không xác định trả về lỗi thay vì panic, và các test batch đều pass. Lưu ý rằng người báo cáo đề nghị mở một PR, nên hãy phối hợp trước khi làm trùng công việc.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
GetBatchResponseById[T] panics when the batch item it is asked for has no body, which is the normal case for a 204 No Content or a 302 item. It also panics when the id is not in the batch response.
The end of the function is:
result, err := parseNode.GetObjectValue(constructor)
return result.(T), err
For an item whose body is null or missing, GetObjectValue returns nil, nil, and result.(T) on a nil interface panics with:
interface conversion: interface is nil, not msgraphgocore.Userable
For an id that is not in the response, resp.GetResponseById(itemId) returns nil, and *item.GetStatus() panics with:
runtime error: invalid memory address or nil pointer dereference
Expected behavior
- An item without a body returns the zero value of
Tand no error. This is what the request adapter's ownSenddoes for a204outside of a batch: I ranreqAdapter.SendwithCreateUseragainst anhttptestserver that answers204, and it returnednil, nil. - An unknown id returns an error instead of panicking. The Python core raises
ValueError("No response found for id: ...")in this case.
How to reproduce
The repo's own test fixture getDummyJSON() in batch_request_test.go already has a 302 item ("1") and a 204 item ("4"), both with "body": null. With the test helpers from batch_request_test.go:
mockServer := makeMockRequest(200, getDummyJSON())
defer mockServer.Close()
reqAdapter.SetBaseUrl(mockServer.URL + "/$batch")
batch := NewBatchRequest(reqAdapter)
_, _ = batch.AddBatchRequestStep(*getRequestInfo())
resp, _ := batch.Send(context.Background(), reqAdapter)
_, err := GetBatchResponseById[Userable](resp, "4", CreateUser) // panics (204, null body)
_, err = GetBatchResponseById[Userable](resp, "1", CreateUser) // panics (302, null body)
_, err = GetBatchResponseById[Userable](resp, "99", CreateUser) // panics (no such id)
On current main (80c76c3) all three panic with the messages above. A 204 item without any body field ({"id":"5","status":204,"headers":{}}) panics the same way.
SDK Version
v1.4.1 / current main (80c76c3)
Latest version known to work for scenario above?
Not known.
Known Workarounds
Check the status code and the body yourself before calling GetBatchResponseById (for example with resp.GetStatusCodes()), and only call it for items that have a body.
Other information
How I found it: I was reading batch_requests.go and noticed the unchecked type assertion; I then ran the fixture cases above.
Where this can show up in practice: a batch of DELETE requests gets 204 items back, and code that loops over its own request ids and calls GetBatchResponseById for each one will panic on the first of them. An unknown id is a caller mistake, but it still should not panic. This is my estimate; I have not seen a field report.
I have a small fix with tests and can open a PR.
- Ngôn ngữ chính
- Go
- Star
- 22
- Fork
- 16
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 microsoftgraph/msgraph-sdk-go-core
-
Erroneous Go race detectionĐang mởstatus:waiting-for-triage type:bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
microsoftgraph/msgraph-sdk-go-core#359 · 1 reaction ·
-
area:authentication goodfirstissue type:enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Improve type validation for PageIteratorCó thể làm lại được @rkodev đã nhận 1013 ngày trước và không có pull request nào đang mở. Đang mởenhancement
microsoftgraph/msgraph-sdk-go-core#267 · 11 bình luận · 1 reaction · 1 người được giao ·
-
Batch "response" semantics are confusingCó thể làm lại được @rkodev đã nhận 1020 ngày trước và không có pull request nào đang mở. Đang mở
microsoftgraph/msgraph-sdk-go-core#250 · 1 bình luận · 1 người được giao ·
-
Default Client OptionsCó thể làm lại được @rkodev đã nhận 1187 ngày trước và không có pull request nào đang mở. Đang mởenhancement
microsoftgraph/msgraph-sdk-go-core#220 · 10 bình luận · 1 người được giao ·
Tất cả issue của microsoftgraph/msgraph-sdk-go-core
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
slavakurilyak/awesome-ai-agents#1026 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
JuliusBrussee/caveman#1567 ·
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 78/100
-
bug postgresql
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày