GetBatchResponseById panics for items without a body (204/302) and for unknown ids
评估
调研方向
从 batch_requests.go 中的 GetBatchResponseById 开始;两个失败点分别是 parseNode.GetObjectValue 之后未检查的 result.(T),以及 *item.GetStatus() 之前未防护的 resp.GetResponseById。复用 batch_request_test.go 中的 fixture 和 helper —— getDummyJSON() 已经包含带有 "body": null 的 302("1")和 204("4")item —— 来添加报告中的三个用例。完成意味着 nil body 会返回零值 T 且没有错误,未知 id 会返回错误而不是 panic,并且 batch 测试通过。注意报告者提出可以开 PR,所以在重复工作之前先协调。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Go
- 星标
- 22
- 派生
- 16
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoftgraph/msgraph-sdk-go-core 的其他 Issue
-
status:waiting-for-triage type:bug
难度 3/5 1-2 天 新手友好度 38/100
microsoftgraph/msgraph-sdk-go-core#359 · 1 个 reaction ·
-
area:authentication goodfirstissue type:enhancement
难度 3/5 1-2 天 新手友好度 45/100
-
Improve type validation for PageIterator可能重新可做 @rkodev 于 1013 天前认领,目前没有进行中的 PR。 未关闭enhancement
microsoftgraph/msgraph-sdk-go-core#267 · 11 条评论 · 1 个 reaction · 已指派 1 人 ·
-
Batch "response" semantics are confusing可能重新可做 @rkodev 于 1020 天前认领,目前没有进行中的 PR。 未关闭
microsoftgraph/msgraph-sdk-go-core#250 · 1 条评论 · 已指派 1 人 ·
-
Default Client Options可能重新可做 @rkodev 于 1187 天前认领,目前没有进行中的 PR。 未关闭enhancement
microsoftgraph/msgraph-sdk-go-core#220 · 10 条评论 · 已指派 1 人 ·
查看 microsoftgraph/msgraph-sdk-go-core 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 62/100
slavakurilyak/awesome-ai-agents#1026 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
JuliusBrussee/caveman#1567 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug postgresql
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复