mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
feat: API endpoint to import dashboards (#11751)
* ImportChartsCommand * feat: add a command to import dashboards * feat: API endpoint to import dashboards * Add dispatcher * Raise specific exception * Fix test * Remove print calls * Add logging when passing
This commit is contained in:
@@ -44,6 +44,7 @@ from superset.databases.commands.exceptions import (
|
||||
DatabaseCreateFailedError,
|
||||
DatabaseDeleteDatasetsExistFailedError,
|
||||
DatabaseDeleteFailedError,
|
||||
DatabaseImportError,
|
||||
DatabaseInvalidError,
|
||||
DatabaseNotFoundError,
|
||||
DatabaseSecurityUnsafeError,
|
||||
@@ -775,6 +776,6 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
except CommandInvalidError as exc:
|
||||
logger.warning("Import database failed")
|
||||
return self.response_422(message=exc.normalized_messages())
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
except DatabaseImportError as exc:
|
||||
logger.exception("Import database failed")
|
||||
return self.response_500(message=str(exc))
|
||||
|
||||
@@ -22,6 +22,7 @@ from superset.commands.exceptions import (
|
||||
CommandInvalidError,
|
||||
CreateFailedError,
|
||||
DeleteFailedError,
|
||||
ImportFailedError,
|
||||
UpdateFailedError,
|
||||
)
|
||||
from superset.security.analytics_db_safety import DBSecurityException
|
||||
@@ -114,3 +115,7 @@ class DatabaseDeleteFailedError(DeleteFailedError):
|
||||
|
||||
class DatabaseSecurityUnsafeError(DBSecurityException):
|
||||
message = _("Stopped an unsafe database connection")
|
||||
|
||||
|
||||
class DatabaseImportError(ImportFailedError):
|
||||
message = _("Import database failed for an unknown reason")
|
||||
|
||||
@@ -51,8 +51,7 @@ class ImportDatabasesCommand(BaseCommand):
|
||||
command.run()
|
||||
return
|
||||
except IncorrectVersionError:
|
||||
# file is not handled by this command, skip
|
||||
pass
|
||||
logger.debug("File not handled by command, skipping")
|
||||
except (CommandInvalidError, ValidationError) as exc:
|
||||
# found right version, but file is invalid
|
||||
logger.info("Command failed validation")
|
||||
|
||||
@@ -29,6 +29,7 @@ from superset.commands.importers.v1.utils import (
|
||||
load_yaml,
|
||||
METADATA_FILE_NAME,
|
||||
)
|
||||
from superset.databases.commands.exceptions import DatabaseImportError
|
||||
from superset.databases.commands.importers.v1.utils import import_database
|
||||
from superset.databases.schemas import ImportV1DatabaseSchema
|
||||
from superset.datasets.commands.importers.v1.utils import import_dataset
|
||||
@@ -75,9 +76,9 @@ class ImportDatabasesCommand(BaseCommand):
|
||||
try:
|
||||
self._import_bundle(db.session)
|
||||
db.session.commit()
|
||||
except Exception as exc:
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
raise exc
|
||||
raise DatabaseImportError()
|
||||
|
||||
def validate(self) -> None:
|
||||
exceptions: List[ValidationError] = []
|
||||
|
||||
Reference in New Issue
Block a user