mirror of
https://github.com/apache/superset.git
synced 2024-09-05 21:37:50 -04:00
fix: DB exported with incorrect type (#16037)
* fix: DB exported with incorrect type * Fix export as well
This commit is contained in:
parent
4cb79e5017
commit
7b15b7690d
@ -18,7 +18,7 @@
|
||||
|
||||
import json
|
||||
import logging
|
||||
from typing import Iterator, Tuple
|
||||
from typing import Any, Dict, Iterator, Tuple
|
||||
|
||||
import yaml
|
||||
from werkzeug.utils import secure_filename
|
||||
@ -32,6 +32,23 @@ from superset.utils.dict_import_export import EXPORT_VERSION
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_extra(extra_payload: str) -> Dict[str, Any]:
|
||||
try:
|
||||
extra = json.loads(extra_payload)
|
||||
except json.decoder.JSONDecodeError:
|
||||
logger.info("Unable to decode `extra` field: %s", extra_payload)
|
||||
return {}
|
||||
|
||||
# Fix for DBs saved with an invalid ``schemas_allowed_for_csv_upload``
|
||||
schemas_allowed_for_csv_upload = extra.get("schemas_allowed_for_csv_upload")
|
||||
if isinstance(schemas_allowed_for_csv_upload, str):
|
||||
extra["schemas_allowed_for_csv_upload"] = json.loads(
|
||||
schemas_allowed_for_csv_upload
|
||||
)
|
||||
|
||||
return extra
|
||||
|
||||
|
||||
class ExportDatabasesCommand(ExportModelsCommand):
|
||||
|
||||
dao = DatabaseDAO
|
||||
@ -51,10 +68,7 @@ class ExportDatabasesCommand(ExportModelsCommand):
|
||||
# TODO (betodealmeida): move this logic to export_to_dict once this
|
||||
# becomes the default export endpoint
|
||||
if payload.get("extra"):
|
||||
try:
|
||||
payload["extra"] = json.loads(payload["extra"])
|
||||
except json.decoder.JSONDecodeError:
|
||||
logger.info("Unable to decode `extra` field: %s", payload["extra"])
|
||||
payload["extra"] = parse_extra(payload["extra"])
|
||||
|
||||
payload["version"] = EXPORT_VERSION
|
||||
|
||||
|
@ -552,6 +552,25 @@ class DatabaseFunctionNamesResponse(Schema):
|
||||
|
||||
|
||||
class ImportV1DatabaseExtraSchema(Schema):
|
||||
# pylint: disable=no-self-use, unused-argument
|
||||
@pre_load
|
||||
def fix_schemas_allowed_for_csv_upload(
|
||||
self, data: Dict[str, Any], **kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Fix ``schemas_allowed_for_csv_upload`` being a string.
|
||||
|
||||
Due to a bug in the database modal, some databases might have been
|
||||
saved and exported with a string for ``schemas_allowed_for_csv_upload``.
|
||||
"""
|
||||
schemas_allowed_for_csv_upload = data.get("schemas_allowed_for_csv_upload")
|
||||
if isinstance(schemas_allowed_for_csv_upload, str):
|
||||
data["schemas_allowed_for_csv_upload"] = json.loads(
|
||||
schemas_allowed_for_csv_upload
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
metadata_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
|
||||
engine_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
|
||||
metadata_cache_timeout = fields.Dict(keys=fields.Str(), values=fields.Integer())
|
||||
|
Loading…
Reference in New Issue
Block a user