BatchRequestItem loses query parameters from RequestInformation
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 src/msgraph_core/requests/batch_request_item.py 中 issue 連結的建構函式行開始,接著比較參照的 kiota-python 檔案中 RequestInformation.url 和 query_parameters 的行為。執行提供的重現程式,以確認 batch body 忽略了這些參數;當查詢參數出現在 batch request body 中時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- Python
- 星號
- 288
- 分支
- 53
- 平均合併
- 8 小時 10 分鐘
- 30 天內合併 PR
- 1
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoftgraph/msgraph-sdk-python-core 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
microsoftgraph/msgraph-sdk-python-core#1116 ·
維護者通常 2 天內回覆
-
status:waiting-for-triage type:bug
難度 2/5 1-3 小時 新手友好度 75/100
microsoftgraph/msgraph-sdk-python-core#1078 ·
維護者通常 2 天內回覆
-
status:waiting-for-triage type:bug
難度 2/5 1-3 小時 新手友好度 68/100
microsoftgraph/msgraph-sdk-python-core#1030 · 3 則留言 · 4 個 reaction ·
維護者通常 2 天內回覆
-
難度 3/5 1-2 天 新手友好度 76/100
microsoftgraph/msgraph-sdk-python-core#1128 ·
維護者通常 2 天內回覆
-
status:waiting-for-triage type:feature
難度 3/5 1-2 天 新手友好度 52/100
microsoftgraph/msgraph-sdk-python-core#1115 ·
維護者通常 2 天內回覆
查看 microsoftgraph/msgraph-sdk-python-core 的全部 Issue
相似的 Issue
-
New Internship未關閉new_internship
難度 1/5 1 小時以內 新手友好度 70/100
-
[BUG] Reports tab: "Unban" button tooltip shows raw `{{ip}}` placeholder instead of the IP address未關閉bug javascript ui
難度 2/5 1-3 小時 新手友好度 68/100
bunkerity/bunkerweb#4001 · 1 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 1/5 1 小時以內 新手友好度 92/100
PedestrianDynamics/pyFDS-Evac#476 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
google/differential-privacy#516 ·
-
難度 2/5 1-3 小時 新手友好度 82/100
adobe-fonts/source-serif#153 ·