Skip to content

Commit e7755f7

Browse files
committed
Recursion fix and minor updates
1 parent 2313157 commit e7755f7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

temporalio/worker/workflow_sandbox/importer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ def restrict_built_in(name: str, orig: Any, *args, **kwargs):
9494
or k in builtin_matcher.use
9595
or k in builtin_matcher.children
9696
):
97+
thread_local = _get_thread_local_builtin(k)
9798
self.restricted_builtins.append(
9899
(
99100
k,
100-
_get_thread_local_builtin(k),
101-
functools.partial(
102-
restrict_built_in, k, getattr(builtins, k)
103-
),
101+
thread_local,
102+
functools.partial(restrict_built_in, k, thread_local.orig),
104103
)
105104
)
106105

@@ -275,18 +274,18 @@ def applied(self, obj: Any, attr: str, current: _T) -> Iterator[None]:
275274
# Function carefully crafted to support nesting and situations where
276275
# other threads may have already set this on obj
277276
orig_current = self.maybe_current
278-
self.current = current
279277
orig_value = getattr(obj, attr)
280278
if orig_value is not self:
281279
setattr(obj, attr, self)
280+
self.current = current
282281
try:
283282
yield None
284283
finally:
284+
setattr(obj, attr, orig_value)
285285
if orig_current is None:
286286
del self.current
287287
else:
288288
self.current = orig_current
289-
setattr(obj, attr, orig_value)
290289

291290
@contextmanager
292291
def unapplied(self) -> Iterator[None]:

temporalio/worker/workflow_sandbox/runner.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def __init__(
3333
self,
3434
*,
3535
restrictions: SandboxRestrictions = SandboxRestrictions.default,
36-
# TODO(cretz): Document that this is re-imported and instantiated for
37-
# _each_ workflow run.
3836
runner_class: Type[WorkflowRunner] = UnsandboxedWorkflowRunner,
3937
) -> None:
4038
"""Create the sandboxed workflow runner.
@@ -102,7 +100,6 @@ def __init__(
102100

103101
# Create the instance
104102
self.globals_and_locals = {
105-
# "__builtins__": __builtins__.copy(), # type: ignore
106103
"__file__": "workflow_sandbox.py",
107104
}
108105
self._create_instance()

0 commit comments

Comments
 (0)