microsoftgraph / microsoftgraph/msgraph-sdk-python

Add members using patch method does not add users to group

オープン
#611 コメント 6 件 リアクション 0 件 担当者 1 名 GitHub で見る

@shemogumbe がすでに取り組んでいます。

2024年8月29日 から。

bug type:documentation
主要言語
Python
スター
630
フォーク
96
平均マージ
15時間 20分
マージ済み PR(30日)
3

説明

Title
Add members using patch method does not add users to group.

Environment
Python Version: 3.10.12
msgraph-sdk version: 1.1.0
OS: Ubuntu 22.04

Stack trace (if available) Screenshot or formatted copy and paste of your stack trace.
N/A

Describe the bug A clear and concise description of what the bug is.

I have the following methods to add a single and multiple users to a group in my AAD B2C tenant. The post method works, and the user is added to the AAD group. The patch method does not work, it returns None and does not raise any exception. I tried the same payload with my user Ids using the MS Graph explorer and users are added successfully. The service principal has full Group, GroupMember and User permissions in the MS Graph API.

async def add_group_member(group_id: str, user_id: str) -> bool:
    """Adds a single user to a group."""
    try:
        if not user_id:
            return False
        
        request_body = ReferenceCreate(odata_id = f'https://graph.microsoft.com/v1.0/directoryObjects/{user_id}')
        await GRAPH_CLIENT.groups.by_group_id(group_id).members.ref.post(request_body)

        return True
    except Exception as e:
        raise e

async def add_group_members(group_id: str, user_ids: List[str]) -> bool:
    """Adds users to a group."""
    try:
        if not user_ids:
            return False
        elif len(user_ids) > 20:
            raise Exception("You can only add 20 users at a time.")
        elif len(user_ids) == 1:
            return await self.add_group_member(group_id, user_ids[0])

        request_body = Group(
            additional_data = {
                "members@odata_bind" : [f'https://graph.microsoft.com/v1.0/directoryObjects/{user_id}' for user_id in user_ids]
            }
        )
        await GRAPH_CLIENT.groups.by_group_id(group_id).patch(request_body)

        return True
    except Exception as e:
        raise e

To Reproduce Steps to reproduce the behavior:
GRAPH_CLIENT = ClientSecretCredentials(...)
add_group_members(group_id, user_ids)

Expected behavior A clear and concise description of what you expected to happen.
Multiple groups added to the group in a single patch request.

Screenshots If applicable, add screenshots to help explain your problem.
N/A

Additional context Add any other context about the problem here.
N/A

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。