superset icon indicating copy to clipboard operation
superset copied to clipboard

Exporting dashboard(s) with REST API creates .json instead of .zip or .yaml

Open krsnik93 opened this issue 5 years ago • 8 comments

I am trying to export and then import back a dashboard by using Superset's REST API. The documentation (https://superset.apache.org/docs/rest-api) for endpoint /dashboard/export states: "Exports multiple Dashboards and downloads them as YAML files." However, the resulting file is seemingly always .json (regardless of number of dashboards exported). Furthermore, when trying to import back into Superset, endpoint /dashboard/import seems to require a .zip file.

So:

  1. Documentation states .yaml file will be created
  2. Exporting actually creates .json file
  3. Import endpoint expects .zip file

Expected results

Expect to be able to export and then import back an unchanged dashboard file.

Actual results

Feb 19 16:27:14 superset gunicorn[15773]: ERROR:root:__init__() got an unexpected keyword argument 'passwords'
Feb 19 16:27:14 superset gunicorn[15773]: Traceback (most recent call last):
Feb 19 16:27:14 superset gunicorn[15773]:   File "/usr/local/lib64/python3.8/site-packages/flask_appbuilder/api/__init__.py", line 84, in wraps
Feb 19 16:27:14 superset gunicorn[15773]:     return f(self, *args, **kwargs)
Feb 19 16:27:14 superset gunicorn[15773]:   File "/usr/local/lib/python3.8/site-packages/superset/views/base_api.py", line 79, in wraps
Feb 19 16:27:14 superset gunicorn[15773]:     duration, response = time_function(f, self, *args, **kwargs)
Feb 19 16:27:14 superset gunicorn[15773]:   File "/usr/local/lib/python3.8/site-packages/superset/utils/core.py", line 1286, in time_function
Feb 19 16:27:14 superset gunicorn[15773]:     response = func(*args, **kwargs)
Feb 19 16:27:14 superset gunicorn[15773]:   File "/usr/local/lib/python3.8/site-packages/superset/dashboards/api.py", line 722, in import_
Feb 19 16:27:14 superset gunicorn[15773]:     command.run()
Feb 19 16:27:14 superset gunicorn[15773]:   File "/usr/local/lib/python3.8/site-packages/superset/dashboards/commands/importers/dispatcher.py", line 57, in run
Feb 19 16:27:14 superset gunicorn[15773]:     command = version(self.contents, *self.args, **self.kwargs)
Feb 19 16:27:14 superset gunicorn[15773]: TypeError: __init__() got an unexpected keyword argument 'passwords'

This error happens in v0.ImportDashboardsCommand in https://github.com/apache/superset/blob/master/superset/dashboards/commands/importers/dispatcher.py. The request should never reach that command as the v1 version is the one that gets executed first. However, version v1 fails because metadata.yaml is not in the uploaded .zip file as per https://github.com/apache/superset/blob/7bef5ab4d23faf571c8cbf2e55a623dac0ee7f64/superset/commands/importers/v1/utils.py.

Screenshots

How to reproduce the bug

  1. Create dashboard
  2. Export dashboard with curl -v --cookie "session=<your_cookie>" --output dashboard.zip http://<your_host>/api/v1/dashboard/export/?q=[<your_dashboard_id>]
  3. do cat dashboard.zip to check that a .json file was created instead
  4. Uploading the file back to /dashboard/import as it was created results in a "Not a zip file" type of error
  5. Zipping the resulting .json from step 2. results in the error described in the previous section as not all needed files are in the archive

Environment

(please complete the following information):

  • superset version: 1.0.0
  • python version: 3.8.6
  • node.js version: node -v

Checklist

Make sure to follow these steps before submitting your issue - thank you!

  • [x] I have checked the superset logs for python stacktraces and included it here as text if there are any.
  • [x] I have reproduced the issue with at least the latest released version of superset.
  • [x] I have checked the issue tracker for the same issue and I haven't found one similar.

krsnik93 avatar Feb 19 '21 17:02 krsnik93

Looping in @betodealmeida and @dpgaspar on this one

willbarrett avatar Feb 19 '21 19:02 willbarrett

@srinify Srini, can you help make sure the doc states the expected behavior? I believe it should yaml though.

junlincc avatar Feb 19 '21 23:02 junlincc

@KrishMunot you need to enable the VERSIONED_EXPORT feature flag to have the dashboard exported as a ZIP file.

As for the error you get, the v0 importer was fixed to take **kwargs in its arguments, so it shouldn't happen anymore.

betodealmeida avatar Apr 01 '21 17:04 betodealmeida

Hi @betodealmeida are you sure you tagged the right dev?

KrishMunot avatar Apr 01 '21 19:04 KrishMunot

Thanks @betodealmeida, just tested this and was able to import back in.

I don't understand why it would depend on VERSIONED_EXPORT though. I would say expected behavior is for VERSIONED_EXPORT either not to affect this or to be enabled by default. Worst case would be to at least mention in the API docs for import/export that it requires this flag, but this is a dirty workaround as (once again) this flag and what it does should not affect import/export functionality.

krsnik93 avatar Apr 01 '21 19:04 krsnik93

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar May 02 '22 07:05 stale[bot]

@KrishMunot you need to enable the VERSIONED_EXPORT feature flag to have the dashboard exported as a ZIP file.

As for the error you get, the v0 importer was fixed to take **kwargs in its arguments, so it shouldn't happen anymore.

Where is this flag documented? As of 2.0.0, is it still available?

yanickrochon avatar Oct 31 '22 20:10 yanickrochon

@KrishMunot you need to enable the VERSIONED_EXPORT feature flag to have the dashboard exported as a ZIP file. As for the error you get, the v0 importer was fixed to take **kwargs in its arguments, so it shouldn't happen anymore.

Where is this flag documented? As of 2.0.0, is it still available?

In Docker image it is superset_config.py FEATURE_FLAGS = {"VERSIONED_EXPORT": True}

samot-samoe avatar Nov 22 '22 10:11 samot-samoe

Since we're now on 3.1, on the verge of 4.0, we're not supporting 2.x or prior versions actively. If anyone is experiencing this issue in current versions, please file a new issue with updated context and repro steps. Thank you for understanding :)

... but yeah... VERSIONED_EXPORT=true ought to fix this.

rusackas avatar Feb 13 '24 20:02 rusackas