From 80a881fe86934ada1b4299879f668f986f6827a8 Mon Sep 17 00:00:00 2001 From: CesarVigario <45819832+CesarVigario@users.noreply.github.com> Date: Thu, 3 Nov 2022 12:27:40 +0000 Subject: [PATCH 1/4] copy_dashboard function variable dup_dashboard_id This error happens when res returns false, with a 503 error, when using an Heroku instance. It will depend on the number and size of Heroku dynos. In my case this issue happened if the Dashboard contained more than 24 cards/questions. However the dashboard was created. We just need to pick the new dashboard id. --- metabase_api/metabase_api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/metabase_api/metabase_api.py b/metabase_api/metabase_api.py index 6d3f07f..0325bd6 100644 --- a/metabase_api/metabase_api.py +++ b/metabase_api/metabase_api.py @@ -1,5 +1,6 @@ import requests import getpass +from time import sleep class Metabase_API(): @@ -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(1) + 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: From 268abc828744b50effd1cfbfcf8b414945e3d858 Mon Sep 17 00:00:00 2001 From: CesarVigario <45819832+CesarVigario@users.noreply.github.com> Date: Thu, 3 Nov 2022 14:19:54 +0000 Subject: [PATCH 2/4] changing sleep duration --- metabase_api/metabase_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metabase_api/metabase_api.py b/metabase_api/metabase_api.py index 0325bd6..4911ae1 100644 --- a/metabase_api/metabase_api.py +++ b/metabase_api/metabase_api.py @@ -808,7 +808,7 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None, 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(1) + sleep(3) 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'] From 22dbd5d51550cc60a92262e8c9a25ea8686ce776 Mon Sep 17 00:00:00 2001 From: CesarVigario <45819832+CesarVigario@users.noreply.github.com> Date: Thu, 3 Nov 2022 15:09:18 +0000 Subject: [PATCH 3/4] Update metabase_api.py --- metabase_api/metabase_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metabase_api/metabase_api.py b/metabase_api/metabase_api.py index 4911ae1..c93db08 100644 --- a/metabase_api/metabase_api.py +++ b/metabase_api/metabase_api.py @@ -808,7 +808,7 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None, 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(3) + sleep(10) 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'] From df39d8f913617b824552c4a8b240f860873c8cee Mon Sep 17 00:00:00 2001 From: CesarVigario <45819832+CesarVigario@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:29:36 +0000 Subject: [PATCH 4/4] Update metabase_api.py --- metabase_api/metabase_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metabase_api/metabase_api.py b/metabase_api/metabase_api.py index c93db08..bbed664 100644 --- a/metabase_api/metabase_api.py +++ b/metabase_api/metabase_api.py @@ -808,7 +808,7 @@ def copy_dashboard(self, source_dashboard_name=None, source_dashboard_id=None, 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(10) + 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']