You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AttributeError: 'NoneType' object has no attribute '__aenter__' when using asyncio.gather #505
i am using the OnBehalfOf-Flow to fetch informations about applications from graphapi.
When using asyncio.gather to "parallelize" multiple requests (e.g. to fetch application infos and application owners) i get this error AttributeError: 'NoneType' object has no attribute '__aenter__.
This is a minimal example the reproduce the error:
This does not only happen when asyncio.gather is used. I make my msgraph api requests by using aiohttp's background tasks, but this also happens.
I found a workaround: use sync version instead async version. For example, using from azure.identity import ClientSecretCredential instead from azure.identity.aio import ClientSecretCredential
I got the same error in an async with asyncio.TaskGroup() as tg: block.
I solved this error by defining GraphServiceClient in the function that I give to tg.create_task().
tasks = []
async with asyncio.TaskGroup() as tg:
for data in temp:
task = tg.create_task(foo(data))
tasks.append(task)
return [task.result() for task in tasks]
I'm using this SDK in Azure Durable Functions. I also get this error and it seems more likely to see it the more requests are being made in a certain time period.
I confirm I have the same issue in Azure (Durable) Functions. I'm using ClientSecretCredential from azure.identity.aio.
It always happens after an inactivity period.
I have the same issue even in local from azure.identity import ClientSecretCredential worked for me. What are the consequences of using the synchronous version of ClientSecretCredential?
What are the consequences of using the synchronous version of ClientSecretCredential?
It may block some parts of the execution. But in my experience with asyncio, multiprocessing, and threading, the GIL doesn't make sure the aio improvement doesn't trickle down into faster execution. So it might not be an issue for you here.
Activity
frejonb commentedon Dec 19, 2023
The issue might be related to this other discussion: Azure/azure-sdk-for-python#32309. We get the same error but we're not using
asyncio.gather.zus666 commentedon Jan 15, 2024
I have the same problem, but with ClientSecretCredential
ntsphwoelfel commentedon Feb 13, 2024
Same here with
ClientSecretCredentialusing it in anAsyncAPIViewwith django rest framework.Christiaan-Mathu commentedon Feb 27, 2024
Same Issue here
pumon commentedon Mar 15, 2024
Same Issue here
[2024-03-15T13:02:17.411Z] ClientSecretCredential.get_token failed: 'NoneType' object has no attribute '__aenter__'arenekosreal commentedon Mar 27, 2024
This does not only happen when
asyncio.gatheris used. I make my msgraph api requests by using aiohttp's background tasks, but this also happens.I found a workaround: use sync version instead async version. For example, using
from azure.identity import ClientSecretCredentialinsteadfrom azure.identity.aio import ClientSecretCredentialmattia-danese commentedon Apr 6, 2024
I got the same error in an
async with asyncio.TaskGroup() as tg:block.I solved this error by defining
GraphServiceClientin the function that I give totg.create_task().ArunJRK commentedon Apr 29, 2024
This solved for me:
changed this
from azure.identity.aio import ClientSecretCredentialto
from azure.identity import ClientSecretCredentialThe synchronous version of
ClientSecretCredentialis not being a problem.danielniccoli commentedon May 6, 2024
I'm using this SDK in Azure Durable Functions. I also get this error and it seems more likely to see it the more requests are being made in a certain time period.
alessnet commentedon May 8, 2024
I confirm I have the same issue in Azure (Durable) Functions. I'm using ClientSecretCredential from azure.identity.aio.
It always happens after an inactivity period.
joan1294 commentedon Jun 25, 2024
I have the same issue even in local
from azure.identity import ClientSecretCredentialworked for me. What are the consequences of using the synchronous version ofClientSecretCredential?ArunJRK commentedon Jun 27, 2024
It may block some parts of the execution. But in my experience with asyncio, multiprocessing, and threading, the GIL doesn't make sure the aio improvement doesn't trickle down into faster execution. So it might not be an issue for you here.
shemogumbe commentedon Oct 29, 2024
Hello Daniel Niccoli (@danielniccoli) thanks for using the SDK and for raising.
On investigating this, it looks to be an issue with Azure_identity's management of sync and async requests rather that on the Graph SDK.
Closing this and moving the workarounds to discussion forums to help anyone who experiences this in the future.