Skip to content

AttributeError: 'async_generator_asend' object has no attribute '__name__' #2340

@hemslo

Description

@hemslo

Describe your environment Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.

opentelemetry-instrumentation-asyncio==0.44b0, error when anext used in asyncio.create_task, because async_generator_asend object has no __name__.

Python 3.11.7, tested on both macos and in linux container.

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.

# anext.py
import asyncio


async def main():
    async def async_gen():
        for i in range(2):
            yield i

    async_gen_instance = async_gen()
    a = anext(async_gen_instance)
    await asyncio.create_task(a)


if __name__ == "__main__":
    asyncio.run(main())
opentelemetry-instrument python3 anext.py

What is the expected behavior?
No error

What is the actual behavior?

AttributeError: 'async_generator_asend' object has no attribute '__name__'. Did you mean: '__ne__'?

Additional context

The exception is thrown from trace_coroutine, anext return async_generator_asend object, it can pass asyncio.iscoroutine check as True, but it doesn't have __name__. Expect either skip this kind of coroutine or construct name differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions