Skip to content

[Bug] RestrictedWorkflowAccessError on async context manager in return close of an activity. #192

Open
@Natim

Description

@Natim

What are you really trying to do?

When using

@register_activity
@activity.defn
async def get_http_response(URL: str) -> dict:
    async with httpx.AsyncClient() as client:
        return await client.get(url)

Describe the bug

We get the following error:

RestrictedWorkflowAccessError
Cannot access threading.local.mro_entries from inside a workflow. If this is code from a module not used in a workflow or known to only be used deterministically from a workflow, mark the import as pass through.

Minimal Reproduction

I believe the workflow sandbox is reactivated before the asynclient __aexit__ code.
Which leads to Temporal thinking its execution is happening in the workflow scope rather than within the activity one.

Environment/Versions

temporal==1.10.0

Additional context

I'm trying to split it in two calls to make it work:

@register_activity
@activity.defn
async def get_http_response(URL: str) -> dict:
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
    return response

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