mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix(OAuth2): Update connection should not fail if connection is missing OAuth2 token (#33100)
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user