Skip to content

asyncio.capture_call_graph: AttributeError walking async-generator ag_await chain #148736

@rajkripal

Description

@rajkripal

In Lib/asyncio/graph.py, _build_graph_for_future uses coro.cr_frame in the ag_await branch:

elif hasattr(coro, 'ag_await'):
    st.append(FrameCallGraphEntry(coro.cr_frame))
    coro = coro.ag_await

Async generators expose ag_frame, not cr_frame, so this raises AttributeError whenever the walk reaches it. The standard async for path routes through async_generator_asend objects which have neither attribute, so the walker hits the else: break first — which is why the test suite doesn't catch it. A coroutine whose cr_await chains directly to an async-generator-shaped object (duck-typed or manually driven) trips the bug.

Introduced in 1885988 (Jan 2025).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions