hughhhh commented on a change in pull request #11332:
URL: 
https://github.com/apache/incubator-superset/pull/11332#discussion_r508905689



##########
File path: superset/datasets/commands/export.py
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# isort:skip_file
+
+import json
+from typing import Iterator, List, Tuple
+
+import yaml
+
+from superset.commands.base import BaseCommand
+from superset.connectors.sqla.models import SqlaTable
+from superset.datasets.commands.exceptions import DatasetNotFoundError
+from superset.datasets.dao import DatasetDAO
+from superset.utils.dict_import_export import IMPORT_EXPORT_VERSION, sanitize
+
+
+class ExportDatasetsCommand(BaseCommand):
+    def __init__(self, dataset_ids: List[int]):
+        self.dataset_ids = dataset_ids
+
+        # this will be set when calling validate()
+        self._models: List[SqlaTable] = []
+
+    @staticmethod
+    def export_dataset(dataset: SqlaTable) -> Iterator[Tuple[str, str]]:
+        database_slug = sanitize(dataset.database.database_name)
+        dataset_slug = sanitize(dataset.table_name)
+        file_name = f"datasets/{database_slug}/{dataset_slug}.yaml"
+
+        payload = dataset.export_to_dict(
+            recursive=True,
+            include_parent_ref=False,
+            include_defaults=True,
+            export_uuids=True,
+        )
+
+        payload["version"] = IMPORT_EXPORT_VERSION
+        payload["database_uuid"] = str(dataset.database.uuid)
+
+        file_content = yaml.safe_dump(payload, sort_keys=False)
+        yield file_name, file_content
+
+        # include database as well
+        file_name = f"databases/{database_slug}.yaml"
+
+        payload = dataset.database.export_to_dict(
+            recursive=False,
+            include_parent_ref=False,
+            include_defaults=True,
+            export_uuids=True,
+        )
+        # TODO (betodealmeida): move this logic to export_to_dict once this
+        # becomes the default export endpoint
+        if "extra" in payload:
+            try:
+                payload["extra"] = json.loads(payload["extra"])
+            except json.decoder.JSONDecodeError:
+                pass

Review comment:
       we should add a error log here specific to `unable to decode`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to