microsoftgraph / microsoftgraph/msgraph-sdk-python-core

Can't deserialize response body from batch request as the json properties are single quoted

オープン
#807 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

P1 priority:p1 type:bug
主要言語
Python
スター
288
フォーク
52
平均マージ
8時間 10分
マージ済み PR(30日)
1

説明

Describe the bug

I'm trying to list applications filtered by particular IDs - there's loads of them so I'm using a batch request with 15 filters at a time (limit). This will allow me to get all the object IDs to query owners etc.

When I attempt to deserialize the BatchResponseContent object with get_response_by_id(response_id, ApplicationCollectionResponse), I get a stack telling me that it can't decode as the properties are single quoted rather than double quoted.

Traceback (most recent call last):
  File "/<project>/.venv/lib/python3.9/site-packages/msgraph_core/requests/batch_response_content.py", line 126, in response_body
    parse_node = ParseNodeFactoryRegistry().get_root_parse_node(
  File "/<project>/.venv/lib/python3.9/site-packages/kiota_abstractions/serialization/parse_node_factory_registry.py", line 41, in get_root_parse_node
    return factory.get_root_parse_node(vendor_specific_content_type, content)
  File "/<project>/.venv/lib/python3.9/site-packages/kiota_abstractions/serialization/parse_node_proxy_factory.py", line 56, in get_root_parse_node
    node = self._concrete.get_root_parse_node(content_type, content)
  File "/<project>/.venv/lib/python3.9/site-packages/kiota_serialization_json/json_parse_node_factory.py", line 37, in get_root_parse_node
    content_dict = json.loads(content_as_str)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

This is backed up by if I just try to do a json_loads(response.body.decode('utf-8')), which then succeeds if I do a .replace("'", '"').

Expected behavior

I should be able to provide the ApplicationCollectionResponse object to BatchResponseContent.get_response_by_id and deserialize the batch response so that I can get the ID out of the response.

How to reproduce
    for app_filter in app_filters:
        app_query_params = (
            ApplicationsRequestBuilder.ApplicationsRequestBuilderGetQueryParameters(
                select=["appId", "id", "serviceManagementReference"],
                filter=f"appId in {app_filter}",
            )
        )
        app_request_config = RequestConfiguration(query_parameters=app_query_params)
        
        batch_request_content.add_request_information(
            client.applications.to_get_request_information(
                request_configuration=app_request_config
            ),
            app_filter,
        )
 
    batch_response = await client.batch.post(batch_request_content)

    if not batch_response or not batch_response.responses:
        log.error("Batch request for application object IDs failed")
        return None

    for response_id in batch_response.responses.keys():
        batch_response.get_response_by_id(response_id, ApplicationCollectionResponse) 
SDK Version

1.17.0 of msgraph-sdk (so 1.2.0 of msgraph-core)

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

msgraph_core/requests/batch_response_content.py から始め、特に response_body と get_response_by_id を確認し、示されているバッチ要求で問題を再現します。シリアル化レジストリに渡されるレスポンス本文を調べ、JSON パーサーの想定と比較します。ApplicationCollectionResponse をバッチレスポンスからデシリアライズでき、アプリケーション ID を取得できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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