Skip to content

Commit

Permalink
Merge pull request #9085 from OpenMined/bschell/asset-repr-fix-privat…
Browse files Browse the repository at this point in the history
…e-data-syft-error

Avoid data access error on asset repr
  • Loading branch information
BrendanSchell authored Jul 25, 2024
2 parents 7324a71 + 85cadff commit 17cfafc
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions packages/syft/src/syft/service/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,21 @@ def _repr_html_(self) -> Any:
else ""
)

if isinstance(self.data, ActionObject):
data_table_line = itables.to_html_datatable(
df=self.data.syft_action_data, css=itables_css
)
elif isinstance(self.data, pd.DataFrame):
data_table_line = itables.to_html_datatable(df=self.data, css=itables_css)
private_data_res = self._private_data()
if private_data_res.is_err():
data_table_line = private_data_res.err_value
else:
data_table_line = self.data
private_data_obj = private_data_res.ok_value
if isinstance(private_data_obj, ActionObject):
data_table_line = itables.to_html_datatable(
df=self.data.syft_action_data, css=itables_css
)
elif isinstance(private_data_obj, pd.DataFrame):
data_table_line = itables.to_html_datatable(
df=private_data_obj, css=itables_css
)
else:
data_table_line = private_data_res.ok_value

if isinstance(self.mock, ActionObject):
mock_table_line = itables.to_html_datatable(
Expand All @@ -176,7 +183,7 @@ def _repr_html_(self) -> Any:
<div class="syft-asset">
<h3>{self.name}</h3>
<p>{self.description}</p>
<p>{self.description or ""}</p>
<p><strong>Asset ID: </strong>{self.id}</p>
<p><strong>Action Object ID: </strong>{self.action_id}</p>
{uploaded_by_line}
Expand Down Expand Up @@ -278,25 +285,36 @@ def has_permission(self, data_result: Any) -> bool:
and data_result.endswith("denied")
)

@property
def data(self) -> Any:
# relative
def _private_data(self) -> Result[Any, str]:
"""
Retrieves the private data associated with this asset.
Returns:
Result[Any, str]: A Result object containing the private data if the user has permission
otherwise an Err object with the message "You do not have permission to access private data."
"""
api = APIRegistry.api_for(
server_uid=self.server_uid,
user_verify_key=self.syft_client_verify_key,
)
if api is None or api.services is None:
return None
return Ok(None)
res = api.services.action.get(self.action_id)
if self.has_permission(res):
return res.syft_action_data
return Ok(res.syft_action_data)
else:
warning = SyftError(
message="You do not have permission to access private data."
)
display(warning, clear=True)
return Err("You do not have permission to access private data.")

@property
def data(self) -> Any:
# relative
private_data_or_error = self._private_data()

if private_data_or_error.is_err():
display(SyftError(message=private_data_or_error.err_value), clear=True)
return None
else:
return private_data_or_error.ok_value


def _is_action_data_empty(obj: Any) -> bool:
Expand Down

0 comments on commit 17cfafc

Please sign in to comment.