microsoftgraph / microsoftgraph/msgraph-sdk-python-core
BatchRequestItem loses query parameters from RequestInformation
Chưa có ai nhận issue này.
- 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 peform a batched GET request with additional query parameters to select specific fields on a response.
The resulting BatchRequestItem is not aware of query parameters and will result in the request being sent without them.
After some debugging I figured out that the underlying problem is the way RequestInformation works.
It's unclear whether this is by design, at least it's very easy to use it incorrectly.
RequestInformation has a public property query_parameters. It also has a url property with getter and setter methods, which deal with __uri internally.
After setting the url property, which results in __uri being truthy, query_parameters will not be evaluated anymore in the url getter, which is used e.g. by BatchRequestItem.
It's unclear whether this is an issue with BatchRequestItem copying the parameters from RequestInformation or whether RequestInformation should include them in the url getter, in which case this issue should be moved to the repo for the microsoft-kiota-abstractions package.
Expected behavior
Query parameters included in the batch body.
How to reproduce
import asyncio
from azure.identity import AzureCliCredential
from msgraph import GraphServiceClient
from kiota_abstractions.request_information import RequestInformation
from kiota_abstractions.method import Method
from msgraph_core.requests.batch_request_item import BatchRequestItem
from msgraph_core.requests.batch_request_content import BatchRequestContent
async def main():
credential = AzureCliCredential()
client = GraphServiceClient(credentials=credential, scopes=["https://graph.microsoft.com/.default"])
request_info = RequestInformation()
request_info.http_method = Method.GET
request_info.url = "/me"
request_info.query_parameters = {
"$select": ",".join([
"id",
"userPrincipalName",
"displayName",
"accountEnabled",
])
}
batch_item = BatchRequestItem(request_information=request_info)
batch_content = BatchRequestContent({batch_item.id: batch_item})
batch_response = await client.batch.post(
batch_request_content=batch_content,
)
print(repr(batch_response.responses.get(batch_item.id).body))
asyncio.run(main())
SDK Version
1.3.8
Latest version known to work for scenario above?
No response
Known Workarounds
Append query parameters to the URL directly, e.g.
query_parameters = {
"$select": ",".join([
"id",
"userPrincipalName",
"displayName",
"accountEnabled",
])
}
request_info.url = "/me?" + urllib.parse.urlencode(query_parameters)
Debug output
N/A
Configuration
No response
Other information
The constructor for BatchRequestItem only takes the URL from the provided RequestInformation, but it doesn't take into account that there may be query parameters, so they're just ignored.
The getter for url on RequestInformation skips any further processing if __url is already truthy: https://github.com/microsoft/kiota-python/blob/microsoft-kiota-abstractions-v1.9.7/packages/abstractions/kiota_abstractions/request_information.py#L97-L102
The setter for url copies the provided URL to __url: https://github.com/microsoft/kiota-python/blob/microsoft-kiota-abstractions-v1.9.7/packages/abstractions/kiota_abstractions/request_information.py#L123-L130
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với src/msgraph_core/requests/batch_request_item.py tại các dòng constructor được liên kết trong issue, sau đó so sánh cách RequestInformation.url và query_parameters hoạt động trong tệp kiota-python được tham chiếu. Chạy reproduction được cung cấp để xác nhận rằng batch body bỏ qua các tham số; hoàn tất khi các tham số truy vấn xuất hiện trong batch request body.
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
- 48/100