Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions temporalio/worker/workflow_sandbox/_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ def set_on_proxy(self, v: _RestrictedProxy) -> None:


class _RestrictedProxyLookup:
bind_func: Callable[[_RestrictedProxy, Any], Callable[..., Any]] | None

def __init__(
self,
access_func: Callable | None = None,
Expand Down Expand Up @@ -951,12 +953,12 @@ def __init__(

def bind_f(instance: _RestrictedProxy, obj: Any) -> Callable:
def i_op(self: Any, other: Any) -> _RestrictedProxy:
f(self, other) # type: ignore
access_func(self, other) # type: ignore
return instance

return i_op.__get__(obj, type(obj)) # type: ignore

self.bind_f = bind_f
self.bind_func = bind_f


_OpF = TypeVar("_OpF", bound=Callable[..., Any])
Expand Down
15 changes: 15 additions & 0 deletions tests/worker/workflow_sandbox/test_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ def test_restricted_proxy_dunder_methods():
assert f"{restricted_path_obj}" == expected_path


def test_restricted_proxy_in_place_operations_preserve_proxy():
restricted_list = _RestrictedProxy(
"list",
list,
RestrictionContext(),
SandboxMatcher(),
)
values = restricted_list([1])

values += [2]

assert type(values) is _RestrictedProxy
assert RestrictionContext.unwrap_if_proxied(values) == [1, 2]


def test_workflow_sandbox_restricted_proxy():
obj_class = _RestrictedProxy(
"RestrictableObject",
Expand Down