You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/03/17 06:55:57 UTC

[GitHub] [superset] melnikovmaksimv commented on issue #19103: CLI import fails when a dataset column has empty `extra` specified

melnikovmaksimv commented on issue #19103:
URL: https://github.com/apache/superset/issues/19103#issuecomment-1070383127


   @betodealmeida i find where bug and fix it
   superset\datasets\commands\export.py
   
   `
    @staticmethod
       def _export(model: SqlaTable) -> Iterator[Tuple[str, str]]:
           database_slug = secure_filename(model.database.database_name)
           dataset_slug = secure_filename(model.table_name)
           file_name = f"datasets/{database_slug}/{dataset_slug}.yaml"
   
           payload = model.export_to_dict(
               recursive=True,
               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
           for key in JSON_KEYS:
               if payload.get(key):
                   try:
                       payload[key] = json.loads(payload[key])
                   except json.decoder.JSONDecodeError:
                       logger.info("Unable to decode `%s` field: %s", key, payload[key])
   
           for column in payload.get("columns", []):
               if column.get("extra"):
                   try:
                       column["extra"] = json.loads(column["extra"])
                   except json.decoder.JSONDecodeError:
                       logger.info("Unable to decode `extra` field: %s", column["extra"])
                       
           for metric in payload.get("metrics", []):
               if metric.get("extra"):
                   try:
                       metric["extra"] = json.loads(metric["extra"])
                   except json.decoder.JSONDecodeError:
                       logger.info("Unable to decode `extra` field: %s", metric["extra"])
   
           payload["version"] = EXPORT_VERSION
           payload["database_uuid"] = str(model.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 = model.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 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["version"] = EXPORT_VERSION
   
           file_content = yaml.safe_dump(payload, sort_keys=False)
           yield file_name, file_content
   `


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org