fix(OAuth2): Update connection should not fail if connection is missing OAuth2 token (#33100)

This commit is contained in:
Vitor Avila
2025-04-14 11:19:55 -03:00
committed by GitHub
parent e1f5c49df7
commit a5a91d5e48
6 changed files with 58 additions and 3 deletions

View File

@@ -138,6 +138,15 @@ class DatabaseConnectionFailedError( # pylint: disable=too-many-ancestors
message = _("Connection failed, please check your connection settings")
class MissingOAuth2TokenError(DatabaseUpdateFailedError):
"""
Exception for when the connection is missing an OAuth2 token
and it's not possible to initiate an OAuth2 dance.
"""
message = _("Missing OAuth2 token")
class DatabaseDeleteDatasetsExistFailedError(DeleteFailedError):
message = _("Cannot delete a database that has datasets attached")

View File

@@ -28,6 +28,7 @@ from superset.commands.database.exceptions import (
DatabaseConnectionFailedError,
DatabaseConnectionSyncPermissionsError,
DatabaseNotFoundError,
MissingOAuth2TokenError,
UserNotFoundInSessionError,
)
from superset.commands.database.utils import (
@@ -115,6 +116,11 @@ class SyncPermissionsCommand(BaseCommand):
try:
alive = ping(engine)
except Exception as err:
if (
self.db_connection.is_oauth2_enabled()
and self.db_connection.db_engine_spec.needs_oauth2(err)
):
raise MissingOAuth2TokenError() from err
raise DatabaseConnectionFailedError() from err
if not alive:

View File

@@ -30,6 +30,7 @@ from superset.commands.database.exceptions import (
DatabaseInvalidError,
DatabaseNotFoundError,
DatabaseUpdateFailedError,
MissingOAuth2TokenError,
)
from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand
from superset.commands.database.ssh_tunnel.delete import DeleteSSHTunnelCommand
@@ -108,7 +109,7 @@ class UpdateDatabaseCommand(BaseCommand):
db_connection=database,
ssh_tunnel=ssh_tunnel,
).run()
except OAuth2RedirectError:
except (OAuth2RedirectError, MissingOAuth2TokenError):
pass
return database