This is an automated email from the ASF dual-hosted git repository.
johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new daf37cbe58 chore: Remove the need for explicit bubble up of certain
exceptions (#29235)
daf37cbe58 is described below
commit daf37cbe585515afe725d266ee6ac292b2a00c44
Author: John Bodley <[email protected]>
AuthorDate: Thu Jun 13 09:36:59 2024 -0700
chore: Remove the need for explicit bubble up of certain exceptions (#29235)
---
superset/charts/data/api.py | 11 ++++++++---
superset/commands/database/ssh_tunnel/create.py | 14 +++++++++-----
superset/tasks/async_queries.py | 11 ++++++++---
superset/utils/decorators.py | 3 ---
4 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py
index 963edc2b3c..ae88fdef5a 100644
--- a/superset/charts/data/api.py
+++ b/superset/charts/data/api.py
@@ -442,10 +442,15 @@ class ChartDataRestApi(ChartRestApi):
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 ea38aa52bf..40083b4b64 100644
--- a/superset/commands/database/ssh_tunnel/create.py
+++ b/superset/commands/database/ssh_tunnel/create.py
@@ -45,15 +45,19 @@ class CreateSSHTunnelCommand(BaseCommand):
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 5be7acc8cc..2fdf094842 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 8e54541e90..3900bdd415 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)