Importing Activities for a Temporal Workflow in Python
A spot where I slipped up in trying to adopt Temporal in an existing Python project and then again in starting a new Python project was in defining a Workflow that invokes an Activity that calls a third party library. Temporal outputs an error message with a long stacktrace that I vaguely understood but didn’t immediately know the solution to
...raise RestrictedWorkflowAccessError(f"{self.name}.{name}")temporalio.worker.workflow_sandbox._restrictions.RestrictedWorkflowAccessError: Cannot access http.server.BaseHTTPRequestHandler.responses 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.
The message itself is very informative “mark the import as pass through”, but requires a follow up search to find the right snippet to get right. I also overlooked the note about importing Activities in Python, mentioned in the Getting Started Guide.
# Import activity, passing it through the sandbox without reloading the modulewith workflow.unsafe.imports_passed_through(): from activities import say_hello
Recommended
Protobuf Zip Imports in Python
In Python, the most straightforward path to implementing a gRPC server for a Protobuf service is to use protoc to generate code that can be imported...
Temporal Parallel Child Workflows
Temporal provides helpful primitives called Workflows and Activities for orchestrating processes. A common pattern I've found useful is the ability...
Using Multiple Temporal Task Queues
Temporal gives you flexibility to define different task queues to route workflows and activities to specific workers. When a worker starts up, it is...