microsoftgraph / microsoftgraph/msgraph-sdk-python

skiptoken for large request responses

未关闭
#176 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
630
派生
96
平均合并
15 小时 20 分钟
30 天内合并 PR
3

描述

I am looking to use the msgraph sdk for python. I want to get a list of devices in our tenant. We have thousands of devices. When using the msgraph.devices.get(), it will return 100 devices (the default limit for msgraph). Utilize the request_query=DevicesRequestBuilder.DevicesRequestBuilderGetQueryParameters(top=100,skip=100)
gives me this error msgraph.generated.models.o_data_errors.o_data_error.ODataError

After some digging in the Microsoft graph explorer for https://graph.microsoft.com/v1.0/devices?$top=100&$skip=100 gives this error

{ "error": { "code": "Request_BadRequest", "message": "'$skip' is not supported by the service.", "innerError": { "date": "2023-04-24T23:08:17", "request-id": "e077ef6b-d848-4fba-8cce-257e7188a6ec", "client-request-id": "4a9beda2-c3ee-0c9f-f012-5308f25f8954" } } }

So, skip is not supported for devices. It is the same in the beta requests.

Since I am able to get the data_data_next_link from my initial devices.get() response, I tried
request_query=DevicesRequestBuilder.DevicesRequestBuilderGetQueryParameters(top=100,skiptoken='RNFw.....')
However, I get an error TypeError: __init__() got an unexpected keyword argument skiptoken
After digging through the code, I modified device_request_builder.py, changing the DevicesRequestBuilderGetQueryParameters(): adding

 if original_name == "skiptoken":
       return "%24skiptoken
......
skiptoken: Optional[str] = None

and class DevicesRequestBuilder(): modifying

self.url_template: str = "{+baseurl}/devices{?%24top,%24skip,%24search,%24filter,%24count,%24orderby,%24select,%24expand,%24skiptoken}

These make the skiptoken available and work with GetQueryParameters.
So basically modifying this module to work with the limitations of msgraph

Is there another way to accomplish paging with devices in this python module?

If not, I can try a pull request for this.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 device_request_builder.py 和 DevicesRequestBuilderGetQueryParameters 类开始,然后将生成的请求与 devices response 的 data_data_next_link 进行比较。验证 skiptoken 在请求 URL 中的表示方式,以及现有的 GetQueryParameters 路径是否可以跟随它。完成标准是:device 分页可以使用返回的 next link 或 skiptoken,且不会出现报告的构造函数错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。