Visitar URL original
[Bug] RestrictedWorkflowAccessError on async context manager in return close of an activity. · Issue #192 · temporalio/samples-python · GitHub
Skip to content

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

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

Activity

  1. added
    bugSomething isn't working
    on Jun 9, 2025
  2. cretz commented on Jun 9, 2025

    @cretz
    Contributor

    Is this activity in the same file as the workflow? The workflow code is reloaded in a sandbox, which includes some of these imports. Can you move the activity to a different file than the workflow and then when you import the activity, make sure you do it under with workflow.unsafe.imports_passed_through():?

  3. Natim commented on Jun 9, 2025

    @Natim
    Author

    I'll try that yes, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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