omarryhan/aiogoogle

Exception "AttributeError: __aenter__" when trying to begin async routine

Closed this issue · 4 comments

I am getting an exception with the following stacktrace (truncated for brevity):

ERROR:root:Traceback (most recent call last): File "/opt/python3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/opt/python3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() async with aiogoogle: AttributeError: __aenter__

ERROR:root:Traceback (most recent call last): File "/opt/python3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/opt/python3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() async with aiogoogle: AttributeError: __aenter__

when running the following lines:

async with aiogoogle:
    async_storage_client = await aiogoogle.discover('storage', 'v1')
    delete_requests = (
        async_storage_client.objects.delete(
            bucket=some_bucket_name, object=filename)
        for filename in filenames)
    await aiogoogle.as_service_account(*delete_requests)

According to the line numbers in the stacktrace, the exception happens on the first line async with aiogoogle:
I wasn't able to find any information about this error. It is also a bit strange since the same code was working fine until recently when running in GCP Cloud Functions python 3.9.

Any suggestions are appreciated!

Very strange indeed.
Can you check if getattr(aiogoogle, '__aenter__') returns anything?

Also, did the AttributeError print any error message? e.g. attribute not found etc.

I was able to resolve the issue. The problem is that the instantiated client name is the same name as the imported module. This causes confusion because Python doesn't complain about it, and instead gives a totally unrelated error.

I'd recommend that you update the documentation to make the client name different from the imported module name so that others don't run into similar issues.

Good idea. Will create a ticket for that