Skip to content

Commit

Permalink
Merge pull request #8463 from OpenMined/output-policy-fix
Browse files Browse the repository at this point in the history
Output policy error handling fix
  • Loading branch information
madhavajay authored Feb 7, 2024
2 parents 2431411 + b181ffd commit d10873f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions packages/syft/src/syft/service/code/user_code_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d10873f

Please sign in to comment.