temporalio / temporalio/samples-python

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

Offen
#192 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
367
Forks
121
Ø Merge
3 T. 20 Std.
Gemergte PRs (30 T.)
11

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das minimale Aktivitätsbeispiel aus dem Issue mit temporal==1.10.0 und httpx.AsyncClient und untersuche anschließend, ob die Workflow-Sandbox-Einschränkungen während aexit des asynchronen Context Managers erneut aktiviert werden. Als abgeschlossen gilt die Aufgabe, wenn die Aktivität die HTTP-Antwort zurückgeben kann, ohne RestrictedWorkflowAccessError auszulösen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.