microsoftgraph / microsoftgraph/msgraph-sdk-python
Group members request gives an incomplete list
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 630
- 分支
- 96
- 平均合併
- 15 小時 20 分鐘
- 30 天內合併 PR
- 3
描述
Describe the bug
I am trying to use Ansible to update membership of an Entra group with managed identities in it. It is misbehaving because the list of members it gets back from the GraphServiceClient is incomplete - in my case, only 20 of the 35 members listed in the Azure portal actually show up, even with the msgraph_beta SDK.
Expected behavior
A list of all the users in the Direct Members section of the group in the Azure portal.
How to reproduce
SP is created with:
az identity create -g {{ resource_group }} -n {{ application_name }}-mi -o json
Attached is a minimal(ish) test example to get members from a group and also fetch a single service principal (that should be in the group but isn't) by object_id. The SP does exist, with odata_type='#microsoft.graph.servicePrincipal'
import asyncio
from msgraph_beta.generated.groups.groups_request_builder import GroupsRequestBuilder
from msgraph_beta.generated.models.group import Group
from msgraph_beta.generated.groups.item.transitive_members.transitive_members_request_builder import \
TransitiveMembersRequestBuilder
from msgraph_beta.generated.groups.item.group_item_request_builder import GroupItemRequestBuilder
from msgraph_beta.generated.models.reference_create import ReferenceCreate
from msgraph_beta.generated.users.item.user_item_request_builder import UserItemRequestBuilder
from msgraph_beta.generated.service_principals.service_principals_request_builder import ServicePrincipalsRequestBuilder
from msgraph_beta import GraphServiceClient
from azure.identity import DefaultAzureCredential
class Blah:
def __init__(self):
self.azure_credential_track2 = DefaultAzureCredential()
self._client = self.get_msgraph_client()
def get_msgraph_client(self):
return GraphServiceClient(self.azure_credential_track2)
async def get_raw_group_members(self, group_id, filters=None):
request_configuration = GroupItemRequestBuilder.GroupItemRequestBuilderGetRequestConfiguration(
query_parameters=GroupItemRequestBuilder.GroupItemRequestBuilderGetQueryParameters(
# this ensures service principals are returned
# see https://learn.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http
expand=["members"]
),
)
if filters:
request_configuration.query_parameters.filter = filters
group = await self._client.groups.by_group_id(group_id).get(request_configuration=request_configuration)
return group.members
async def get_user(self, user_id):
req = ServicePrincipalsRequestBuilder.ServicePrincipalsRequestBuilderGetRequestConfiguration(
query_parameters=ServicePrincipalsRequestBuilder.ServicePrincipalsRequestBuilderGetRequestConfiguration()
)
user = await self._client.service_principals.by_service_principal_id(user_id).get(request_configuration=req)
return user
def test(self, group_id):
ret = asyncio.get_event_loop().run_until_complete(self.get_raw_group_members(group_id))
current_members = [(object.id, object.display_name, object.odata_type) for object in ret]
return current_members
def test2(self, user_id):
ret = asyncio.get_event_loop().run_until_complete(self.get_user(user_id=user_id))
print(ret)
def main():
group_id = "XXXXXX-YYYY-4e07-a3ab-6de8cbd4e560"
user_id = "XXXXXX-YYYY-4b39-9842-0a1e617f6497"
t = Blah()
cm = t.test(group_id)
print("========================")
for c in cm:
print(f" {c[0]} {c[2]} {c[1]}")
t.test2(user_id)
if __name__ == "__main__":
main()
SDK Version
No response
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
- Linux (ubuntu 24.04) on x64
- Python 3.12 (same in 3.11)
- msgraph-beta-sdk 1.33.0
- msgraph-core 1.3.3
- msgraph-sdk 1.6.0
### Other information
_No response_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
該 issue 沒有指出任何儲存庫檔案或測試。先使用列出的 msgraph-beta-sdk 和 msgraph-core 版本執行提供的 Python 重現程式,然後檢查 GraphServiceClient 的群組成員要求及其分頁或展開行為。完成標準是 SDK 傳回群組的所有直接成員(包括 service principal),而不是僅傳回前 20 個。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- ansible, azure, python
- 領域
- api, backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100