Skip to content

Commit

Permalink
Add permissions check for delta table reading (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
irenedea committed Sep 12, 2024
1 parent 5465db4 commit dab768f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions llmfoundry/command_utils/data_prep/convert_delta_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ClusterDoesNotExistError,
FailedToConnectToDatabricksError,
FailedToCreateSQLConnectionError,
InsufficientPermissionsError,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -454,6 +455,12 @@ def fetch(
sparkSession,
)
except Exception as e:
from pyspark.errors import AnalysisException
if isinstance(e, AnalysisException):
if 'INSUFFICIENT_PERMISSIONS' in e.message: # pyright: ignore
raise InsufficientPermissionsError(
action=f'reading from {tablename}',
) from e
raise RuntimeError(
f'Error in get rows from {tablename}. Restart sparkSession and try again',
) from e
Expand Down
8 changes: 8 additions & 0 deletions llmfoundry/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,11 @@ def __init__(
window_size=window_size,
loss_window=loss_window,
)


class InsufficientPermissionsError(UserError):
"""Error thrown when the user does not have sufficient permissions."""

def __init__(self, action: str) -> None:
message = f'Insufficient permissions when {action}. Please check your permissions.'
super().__init__(message, action=action)

0 comments on commit dab768f

Please sign in to comment.