microsoftgraph / microsoftgraph/msgraph-sdk-python-core

Adding request info does not use specified request_id for BatchRequestContent

Đang mở
#810 0 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

Trying to add batch request steps with custom request IDs so that I can track the responses, however the custom request ID is always overridden to a random uuid

Expected behavior

Should be able to specify a custom request ID as specified in the function doc strings and in samples.

How to reproduce

You can track this through:

msgraph_core/requests/batch_request_content.py

    def add_request_information(
        self, request_information: RequestInformation, request_id: Optional[str] = None
    ) -> None:
        """
        Adds a request to the batch request content.
        Args:
            request_information (RequestInformation): The request information to add.
            request_id: Optional[str]: The request id to add.
        """
        request_id = request_id if request_id else str(uuid.uuid4())
        self.add_request(request_id, BatchRequestItem(request_information))

When creating the BatchRequestItem (msgraph_core/requests/batch_request_item.py), we've not passed the request ID into the init, so a random one is assigned to the Item:

    def __init__(
        self,
        request_information: Optional[RequestInformation] = None,
        id: str = "",
        depends_on: Optional[list[Union[str, 'BatchRequestItem']]] = []
    ):
        """
        Initializes a new instance of the BatchRequestItem class.
        Args:
            request_information (RequestInformation): The request information.
            id (str, optional): The ID of the request item. Defaults to "".
            depends_on (Optional[list[Union[str, BatchRequestItem]], optional):
            The IDs of the requests that this request depends on. Defaults to None.
        """
        if request_information is None or not request_information.http_method:
            raise ValueError("HTTP method cannot be Null/Empty")
        self._id = id or str(uuid4())

The custom one is then only used if there isn't one already on the request, which is impossible here because of the initialisation of the item object:

    def add_request(self, request_id: Optional[str], request: BatchRequestItem) -> None:
        """
        Adds a request to the batch request content.
        Args:
            request_id (Optional[str]): The request id to add.
            request (BatchRequestItem): The request to add.
        """
        if len(self.requests) >= BatchRequestContent.MAX_REQUESTS:
            raise RuntimeError(f"Maximum number of requests is {BatchRequestContent.MAX_REQUESTS}")
        if not request.id:
            request.id = request_id if request_id else str(uuid.uuid4())

So it's impossible for you to set a custom request ID through the add_request_information function. Either we should pass the custom one into the initialisation of the Item, or the "add_request" function should be checking for whether we have a request_id not a request.id. Suspect it should be the latter otherwise the function signature makes no sense.

SDK Version

1.17.0 of the SDK, 1.20.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_request_content.py tại add_request_information và theo dõi cách BatchRequestItem được tạo trong msgraph_core/requests/batch_request_item.py. Xác minh rằng request_id được cung cấp vẫn là ID của mục và rằng các ID được tạo vẫn hoạt động khi không cung cấp ID tùy chỉnh.

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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/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.