Closed northpowered closed 1 year ago
This is due to a known issue with the sandbox when imports extend restricted classes like datetime
. See https://github.com/temporalio/sdk-python/tree/0.1b3#extending-restricted-classes. Hopefully this will be fixed in a release coming soon, but in the meantime, you need to mark loguru
as a "passthrough module" (https://github.com/temporalio/sdk-python/tree/0.1b3#passthrough-modules), e.g.:
my_restrictions = dataclasses.replace(
SandboxRestrictions.default,
passthrough_modules=SandboxRestrictions.passthrough_modules_default | SandboxMatcher(access={"loguru"}),
)
my_worker = Worker(..., workflow_runner=SandboxedWorkflowRunner(restrictions=my_restrictions))
We have made this easier in main
which should be released shortly.
@cretz This works great, tnx a lot! Adding some modules to custom restrictions should look like this?
access={"loguru","pydantic"}
Yes, but that is going to change in a couple of days :-) See the equivalent section on main
at https://github.com/temporalio/sdk-python#passthrough-modules (though hopefully this bug won't surface unless you actually try to use the logger in the workflow file/class which you probably shouldn't).
Thanx, we`re not using logging right in the workflows :-)
Closed
What are you really trying to do?
I`m trying to use Loguru module with temporal-sdk code
OS: Ubuntu 22.04 LTS 5.15.0-33-generic
or
Describe the bug
Imports like these raise this:
Long traceback, CLICK to expand
Traceback (most recent call last): File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/_workflow.py", line 113, in __init__ workflow_runner.prepare_workflow(defn) File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_runner.py", line 53, in prepare_workflow self.create_instance( File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_runner.py", line 87, in create_instance return _Instance(det, self._runner_class, self._restrictions) File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_runner.py", line 107, in __init__ self._create_instance() File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_runner.py", line 118, in _create_instance self._run_code( File "/home/northstar/.cache/pypoetry/virtualenvs/alif-interactor-tmPkMBix-py3.10/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_runner.py", line 160, in _run_code exec(code, self.globals_and_locals, self.globals_and_locals) File "Some notes:
For example (this is working fine)