Skip to content

Async resource is sometimes None #539

Open
@tymokvo

Description

@tymokvo

Hello, I am trying to provide a long-lived aiohttp.ClientSession for integrating with an external HTTP API.

I have an async generator for the resource defined as:

async def http_session_factory(*args, **kwargs):
    session = ClientSession(*args, **kwargs)

    yield session

    if not session.closed:
        await session.close()

which is then added to the DeclarativeContainer with providers.Resource(http_session_factory).

But, my application is intermittently throwing:

AttributeError: 'NoneType' object has no attribute 'request'"

when trying to use the provided ClientSession instance.

Am I initializing this incorrectly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions