microsoftgraph / microsoftgraph/msgraph-sdk-python-core

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

Đang mở
#807 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

P1 priority:p1 type:bug
Ngôn ngữ chính
Python
Star
288
Fork
52
Merge trung bình
8 giờ 10 phút
Pull request đã merge (30 ngày)
1

Mô tả

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_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong msgraph_core/requests/batch_response_content.py, đặc biệt là response_body và get_response_by_id, rồi tái hiện vấn đề với yêu cầu batch được hiển thị. Kiểm tra phần nội dung phản hồi được truyền vào registry tuần tự hóa và so sánh với các yêu cầu của trình phân tích cú pháp JSON. Công việc được xem là hoàn tất khi có thể giải tuần tự ApplicationCollectionResponse từ phản hồi batch và lấy được ID ứng dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.