Description
What are you really trying to do?
Pass model and activity modules through the workflow sandbox so they can be reused across workflow runs.
Describe the bug
Inside workflow.unsafe.imports_passed_through(), from pkg import models reloads pkg.models in the sandbox when the workflow also lives in pkg. Changing the import to import pkg.models as models reuses the host module.
The expected behaviour is that both forms should reuse it.
How did you hit this issue?
I have workflows and models in the same package, and was trying to usefrom package import module for these imports inside a passthrough block.
Minimal Reproduction
Create these files and pkg/__init__.py.
pkg/models.py
from temporalio import workflow
imported_in_sandbox = workflow.unsafe.in_sandbox()pkg/workflows.py
from temporalio import workflow
with workflow.unsafe.imports_passed_through():
from pkg import models
@workflow.defn
class CheckImport:
@workflow.run
async def run(self) -> bool:
return models.imported_in_sandboxmain.py
import asyncio
from temporalio import testing, worker
from pkg.workflows import CheckImport
async def main() -> None:
async with await testing.WorkflowEnvironment.start_local() as env:
async with worker.Worker(env.client, task_queue="repro", workflows=[CheckImport]):
result = await env.client.execute_workflow(CheckImport.run, id="repro", task_queue="repro")
print(result)
asyncio.run(main())Run python main.py. Then change from pkg import models to import pkg.models as models and run it again.
from pkg import models prints True and import pkg.models as models prints False. The expected behaviour is that both print false.
Environment/Versions
- OS and processor: macOS 26, M2 Pro
- Temporal Version: Temporal CLI 1.10.0/Server 1.32.2/SDK 1.36.1
- Are you using Docker or Kubernetes or building Temporal from source? No
Activity