From f219dc179413948b4c204c69b4ef24042518455a Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Fri, 30 May 2025 13:04:04 -0400 Subject: [PATCH] chore: make DB syntax errors 400 (#33619) --- superset/commands/database/test_connection.py | 6 ++++-- superset/commands/database/validate.py | 2 +- tests/integration_tests/databases/api_tests.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/superset/commands/database/test_connection.py b/superset/commands/database/test_connection.py index 3c16730d00b..1e5fb8db44d 100644 --- a/superset/commands/database/test_connection.py +++ b/superset/commands/database/test_connection.py @@ -89,7 +89,9 @@ class TestConnectionDatabaseCommand(BaseCommand): self._context = context self._uri = uri - def run(self) -> None: # pylint: disable=too-many-statements,too-many-branches # noqa: C901 + def run( # noqa: C901 + self, + ) -> None: # pylint: disable=too-many-statements,too-many-branches self.validate() ex_str = "" ssh_tunnel = self._properties.get("ssh_tunnel") @@ -188,7 +190,7 @@ class TestConnectionDatabaseCommand(BaseCommand): ) # check for custom errors (wrong username, wrong password, etc) errors = database.db_engine_spec.extract_errors(ex, self._context) - raise SupersetErrorsException(errors) from ex + raise SupersetErrorsException(errors, status=400) from ex except OAuth2RedirectError: raise except SupersetSecurityException as ex: diff --git a/superset/commands/database/validate.py b/superset/commands/database/validate.py index eda5d75bed8..41f5ce3e19d 100644 --- a/superset/commands/database/validate.py +++ b/superset/commands/database/validate.py @@ -125,7 +125,7 @@ class ValidateDatabaseParametersCommand(BaseCommand): "database": url.database, } errors = database.db_engine_spec.extract_errors(ex, context) - raise DatabaseTestConnectionFailedError(errors) from ex + raise DatabaseTestConnectionFailedError(errors, status=400) from ex if not alive: raise DatabaseOfflineError( diff --git a/tests/integration_tests/databases/api_tests.py b/tests/integration_tests/databases/api_tests.py index 0c6dad0b1df..3bf5d7d7652 100644 --- a/tests/integration_tests/databases/api_tests.py +++ b/tests/integration_tests/databases/api_tests.py @@ -1337,7 +1337,7 @@ class TestDatabaseApi(SupersetTestCase): expected_response_postgres = { "errors": [dataclasses.asdict(superset_error_postgres)] } - assert response.status_code == 500 + assert response.status_code == 400 if example_db.backend == "mysql": assert response_data == expected_response_mysql else: @@ -2450,7 +2450,7 @@ class TestDatabaseApi(SupersetTestCase): url = "api/v1/database/test_connection/" rv = self.post_assert_metric(url, data, "test_connection") - assert rv.status_code == 500 + assert rv.status_code == 400 assert rv.headers["Content-Type"] == "application/json; charset=utf-8" response = json.loads(rv.data.decode("utf-8")) expected_response = {"errors": [dataclasses.asdict(superset_error)]}