msgraph-sdk-python-core icon indicating copy to clipboard operation
msgraph-sdk-python-core copied to clipboard

graph client from msgrpah-core only give users for latest created graph client

Open amitdwivedi-broadcom opened this issue 1 year ago • 1 comments

  • msgraph-core:
  • Version: 0.2.2:
  • OS: Mac:
  • Python Version- 3.10.6:

I have two active directories on two different azure accounts, one has around x number of users and another has y number of users then i create two graph client objects these two account and try call get user api for both clients, but almost every time i get the same output.

example Acct1 = 33 users Acct2 = 15 users

object created in order graphclientforacct1 - first ¯ graphclientforacct2 - second

output graphclientforacct1.get(/user) - this comes as 15 where as expected output was 33 graphclientforacct1.get(/user) - this comes as 15

if i change the object creation order it gives 33 users for both client. Looks like the last created object is somehow set and graph client is only using that.

Sample Script:

from msgraph.core import GraphClient from azure.mgmt.storage import StorageManagementClient import os import json from azure.identity import ClientSecretCredential from msgraph.core import GraphClient

#33users cred1 = ClientSecretCredential( client_id="blah blah", client_secret="blah blah", tenant_id="blah blah" ) #25 user cred2 = ClientSecretCredential( client_id="blah blah", client_secret="blah blah", tenant_id="blah blah")

cred2obj = GraphClient(credential=cred2)# 25 user cred1obj = GraphClient(credential=cred1)# 33 users

clientobjList = [cred1obj, cred2obj]

for client in clientobjList: users = client.get('/users') data = json.loads(users.text)['value'] return_val = [] from collections import namedtuple for row in data: return_val.append(namedtuple('x', row.keys())(*row.values()))

with open("myfile.txt", 'a') as file1:
    file1.write("\n==========="  +"======================\n",)
    if len(return_val):
        for value in return_val:
                file1.write(str(value[1]))
    file1.write("\n==========="+ str(len(return_val))+"======================\n",)

print('done')

Another attempt with sessions too - this also fails

from msgraph.core import GraphClient from azure.mgmt.storage import StorageManagementClient import os import json from azure.identity import ClientSecretCredential from msgraph.core import GraphClient import requests

#33users cred1 = ClientSecretCredential( client_id="blah blah", client_secret="blah blah", tenant_id="blah blah" ) #25 user cred2 = ClientSecretCredential( client_id="blah blah", client_secret="blah blah", tenant_id="blah blah")

session1 = requests.Session() session2 = requests.Session() cred2obj = GraphClient(credential=cred2, session=session2)
cred1obj = GraphClient(credential=cred1, session=session1)

clientobjList = [cred1obj, cred2obj]

for client in clientobjList: users = client.get('/users') data = json.loads(users.text)['value'] return_val = [] from collections import namedtuple for row in data: return_val.append(namedtuple('x', row.keys())(*row.values()))

with open("myfile.txt", 'a') as file1:
    file1.write("\n==========="  +"======================\n",)
    if len(return_val):
        for value in return_val:
                file1.write(str(value[1]))
    file1.write("\n==========="+ str(len(return_val))+"======================\n",)

print('done')

amitdwivedi-broadcom avatar Sep 28 '22 19:09 amitdwivedi-broadcom