From 40bf2ab167e73aad9acad061206c2b110dc48fae Mon Sep 17 00:00:00 2001 From: Koen van der Veen Date: Tue, 6 Feb 2024 17:39:02 +0000 Subject: [PATCH 1/2] add new property to usercode, change error handling --- packages/syft/src/syft/service/code/user_code.py | 4 ++++ packages/syft/src/syft/service/code/user_code_service.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index 020830d2508..a449845115d 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -462,6 +462,10 @@ def input_policy(self) -> Optional[InputPolicy]: print(f"Failed to deserialize custom input policy state. {e}") return None + @property + def output_policy_approved(self): + return self.status.approved + @property def output_policy(self) -> Optional[OutputPolicy]: if not self.status.approved: diff --git a/packages/syft/src/syft/service/code/user_code_service.py b/packages/syft/src/syft/service/code/user_code_service.py index 20c8630c231..da409b1dac0 100644 --- a/packages/syft/src/syft/service/code/user_code_service.py +++ b/packages/syft/src/syft/service/code/user_code_service.py @@ -311,7 +311,7 @@ def is_execution_allowed(self, code, context, output_policy): # Check if the user has permission to execute the code. elif not (has_code_permission := self.has_code_permission(code, context)): return has_code_permission - elif code.output_policy is None: + elif not code.output_policy_approved: return SyftError("Output policy not approved", code) elif not output_policy.valid: return output_policy.valid @@ -399,9 +399,9 @@ def _call( code=code, context=context, output_policy=output_policy ) if not can_execute: - if output_policy is None: + if not code.output_policy_approved: return Err( - "UserCodeStatus.DENIED: Function has no output policy" + "Execution denied: Your code is waiting for approval" ) if not (is_valid := output_policy.valid): if ( From b181ffd9b07f0bee3d4132884db7024a1677ea20 Mon Sep 17 00:00:00 2001 From: Koen van der Veen Date: Tue, 6 Feb 2024 17:41:59 +0000 Subject: [PATCH 2/2] fix test --- .../syft/tests/syft/request/request_code_accept_deny_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/tests/syft/request/request_code_accept_deny_test.py b/packages/syft/tests/syft/request/request_code_accept_deny_test.py index 242de50ff85..7451dd26d91 100644 --- a/packages/syft/tests/syft/request/request_code_accept_deny_test.py +++ b/packages/syft/tests/syft/request/request_code_accept_deny_test.py @@ -205,4 +205,4 @@ def simple_function(data): result = ds_client.code.simple_function(data=action_obj) assert isinstance(result, SyftError) - assert "UserCodeStatus.DENIED" in result.message + assert "Execution denied" in result.message