Skip to content

Commit

Permalink
chore: Remove the need for explicit bubble up of certain exceptions (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Jun 13, 2024
1 parent f185bbe commit daf37cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
11 changes: 8 additions & 3 deletions superset/charts/data/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,15 @@ def _map_form_data_datasource_to_dataset_id(
def _create_query_context_from_form(
self, form_data: dict[str, Any]
) -> QueryContext:
"""
Create the query context from the form data.
:param form_data: The chart form data
:returns: The query context
:raises ValidationError: If the request is incorrect
"""

try:
return ChartDataQueryContextSchema().load(form_data)
except KeyError as ex:
raise ValidationError("Request is incorrect") from ex
except ValidationError: # pylint: disable=try-except-raise
# Make sure to bubble this up
raise
14 changes: 9 additions & 5 deletions superset/commands/database/ssh_tunnel/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ def __init__(self, database: Database, data: dict[str, Any]):
self._database = database

def run(self) -> Model:
"""
Create an SSH tunnel.
:returns: The SSH tunnel model
:raises SSHTunnelCreateFailedError: If the model creation fails
:raises SSHTunnelInvalidError: If the configuration are invalid
"""

try:
self.validate()
ssh_tunnel = SSHTunnelDAO.create(attributes=self._properties, commit=False)
return ssh_tunnel
return SSHTunnelDAO.create(attributes=self._properties, commit=False)
except DAOCreateFailedError as ex:
raise SSHTunnelCreateFailedError() from ex
except SSHTunnelInvalidError: # pylint: disable=try-except-raise
# Make sure to bubble this up
raise

def validate(self) -> None:
# TODO(hughhh): check to make sure the server port is not localhost
Expand Down
11 changes: 8 additions & 3 deletions superset/tasks/async_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ def set_form_data(form_data: dict[str, Any]) -> None:


def _create_query_context_from_form(form_data: dict[str, Any]) -> QueryContext:
"""
Create the query context from the form data.
:param form_data: The task form data
:returns: The query context
:raises ValidationError: If the request is incorrect
"""

try:
return ChartDataQueryContextSchema().load(form_data)
except KeyError as ex:
raise ValidationError("Request is incorrect") from ex
except ValidationError: # pylint: disable=try-except-raise
# Make sure to bubble this up
raise


def _load_user_from_job_metadata(job_metadata: dict[str, Any]) -> User:
Expand Down
3 changes: 0 additions & 3 deletions superset/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ def stats_timing(stats_key: str, stats_logger: BaseStatsLogger) -> Iterator[floa
start_ts = now_as_float()
try:
yield start_ts
except Exception: # pylint: disable=try-except-raise
# Make sure to bubble this up
raise
finally:
stats_logger.timing(stats_key, now_as_float() - start_ts)

Expand Down

0 comments on commit daf37cb

Please sign in to comment.