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 2019/07/18 05:21:07 UTC

[GitHub] [incubator-superset] mistercrunch commented on a change in pull request #7879: Remove unnecessary fields from dashboard exported json

mistercrunch commented on a change in pull request #7879: Remove unnecessary fields from dashboard exported json
URL: https://github.com/apache/incubator-superset/pull/7879#discussion_r304738127
 
 

 ##########
 File path: superset/models/core.py
 ##########
 @@ -658,37 +661,49 @@ def export_dashboards(cls, dashboard_ids):
         for dashboard_id in dashboard_ids:
             # make sure that dashboard_id is an integer
             dashboard_id = int(dashboard_id)
-            copied_dashboard = (
+            dashboard = (
                 db.session.query(Dashboard)
                 .options(subqueryload(Dashboard.slices))
                 .filter_by(id=dashboard_id)
                 .first()
             )
-            make_transient(copied_dashboard)
-            for slc in copied_dashboard.slices:
-                make_transient(slc)
+            # remove ids and relations (like owners, created by, slices, ...)
+            copied_dashboard = dashboard.copy()
+            for slc in dashboard.slices:
                 datasource_ids.add((slc.datasource_id, slc.datasource_type))
+                copied_slc = slc.copy()
+                # save original id into json
+                # we need it to update dashboard's json metadata on import
+                copied_slc.id = slc.id
                 # add extra params for the import
-                slc.alter_params(
+                copied_slc.alter_params(
                     remote_id=slc.id,
                     datasource_name=slc.datasource.name,
                     schema=slc.datasource.schema,
                     database_name=slc.datasource.database.name,
                 )
+                # set slices without creating ORM relations
+                slices = copied_dashboard.__dict__.setdefault("slices", [])
+                slices.append(copied_slc)
             copied_dashboard.alter_params(remote_id=dashboard_id)
             copied_dashboards.append(copied_dashboard)
 
             eager_datasources = []
-            for dashboard_id, dashboard_type in datasource_ids:
+            for datasource_id, datasource_type in datasource_ids:
 
 Review comment:
   Oh wow, that was super wrong / confusing naming that somehow works...  I dug down the `git blame` rabbit hole out of curiosity to `2016-10-11`, 73cd2ea3b

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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