Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing copy_dashboard for Metabase hosted in Heroku #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion metabase_api/metabase_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import getpass
from time import sleep

class Metabase_API():

Expand Down Expand Up @@ -801,7 +802,15 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None,
### shallow-copy
shallow_copy_json = {'collection_id':destination_collection_id, 'name':destination_dashboard_name}
res = self.post('/api/dashboard/{}/copy'.format(source_dashboard_id), json=shallow_copy_json)
dup_dashboard_id = res['id']

try:
dup_dashboard_id = res['id']
except TypeError:
# This error happens when res returns false, with a 503 error, when using an Heroku instance.
# However the dashboard was created. We just need to pick the new dashboard id.
sleep(20)
dashboards = self.get("/api/dashboard/")
dup_dashboard_id = sorted([x for x in dashboards if x['name'] == destination_dashboard_name], key=lambda k: k['created_at'], reverse=True)[0]['id']

### deepcopy
if deepcopy:
Expand Down