diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py index 963edc2b3c6df..ae88fdef5ad15 100644 --- a/superset/charts/data/api.py +++ b/superset/charts/data/api.py @@ -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 diff --git a/superset/commands/database/ssh_tunnel/create.py b/superset/commands/database/ssh_tunnel/create.py index ea38aa52bfa4f..40083b4b648aa 100644 --- a/superset/commands/database/ssh_tunnel/create.py +++ b/superset/commands/database/ssh_tunnel/create.py @@ -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 diff --git a/superset/tasks/async_queries.py b/superset/tasks/async_queries.py index 5be7acc8ccafe..2fdf094842e01 100644 --- a/superset/tasks/async_queries.py +++ b/superset/tasks/async_queries.py @@ -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: diff --git a/superset/utils/decorators.py b/superset/utils/decorators.py index 8e54541e90cde..3900bdd4156a1 100644 --- a/superset/utils/decorators.py +++ b/superset/utils/decorators.py @@ -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)