GetBatchResponseById panics for items without a body (204/302) and for unknown ids

オープン 初心者向け
#449 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@0z5a がすでに取り組んでいます。

2026年11月23日 から。

  • #450 @0z5a による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
api

調査の方向性

batch_requests.go の GetBatchResponseById から始めてください。失敗箇所は 2 つあり、parseNode.GetObjectValue の後の未チェックの result.(T) と、*item.GetStatus() の前の未保護の resp.GetResponseById です。batch_request_test.go の fixture と helper を再利用し — getDummyJSON() にはすでに 302("1")と 204("4")の item が "body": null 付きで含まれています —、レポートの 3 つのケースを追加してください。完了条件は、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 T and no error. This is what the request adapter's own Send does for a 204 outside of a batch: I ran reqAdapter.Send with CreateUser against an httptest server that answers 204, and it returned nil, 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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoftgraph/msgraph-sdk-go-core のほかの issue

microsoftgraph/msgraph-sdk-go-core の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。