Skip to content

Commit 7d51f3b

Browse files
committed
Fix update_dashboard to also handle folderUid well
1 parent 5cb4711 commit 7d51f3b

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## unreleased
4+
- Fixed `update_dashboard` to also handle `folderUid` well. Thanks, @CantankerousBullMoose.
45

56
## 4.3.0 (2025-02-08)
67
- Added support for querying all data source-managed alerts. Thanks, @dmyerscough.

grafana_client/elements/_async/dashboard.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ async def update_dashboard(self, dashboard):
4040
:return:
4141
"""
4242

43-
# When the "folderId" is not available within the dashboard payload,
44-
# populate it from the nested "meta" object, if given.
45-
if "folderId" not in dashboard:
46-
if "meta" in dashboard and "folderId" in dashboard["meta"]:
47-
dashboard = dashboard.copy()
48-
dashboard["folderId"] = dashboard["meta"]["folderId"]
43+
# When `folderId` or `folderUid` are not available within the dashboard payload,
44+
# populate them from the nested `meta` object, when given.
45+
for attribute in ["folderId", "folderUid"]:
46+
if attribute not in dashboard:
47+
if "meta" in dashboard and attribute in dashboard["meta"]:
48+
dashboard = dashboard.copy()
49+
dashboard[attribute] = dashboard["meta"][attribute]
4950

5051
put_dashboard_path = "/dashboards/db"
5152
return await self.client.POST(put_dashboard_path, json=dashboard)

grafana_client/elements/dashboard.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ def update_dashboard(self, dashboard):
4040
:return:
4141
"""
4242

43-
# When the "folderId" is not available within the dashboard payload,
44-
# populate it from the nested "meta" object, if given.
45-
if "folderId" not in dashboard:
46-
if "meta" in dashboard and "folderId" in dashboard["meta"]:
47-
dashboard = dashboard.copy()
48-
dashboard["folderId"] = dashboard["meta"]["folderId"]
43+
# When `folderId` or `folderUid` are not available within the dashboard payload,
44+
# populate them from the nested `meta` object, when given.
45+
for attribute in ["folderId", "folderUid"]:
46+
if attribute not in dashboard:
47+
if "meta" in dashboard and attribute in dashboard["meta"]:
48+
dashboard = dashboard.copy()
49+
dashboard[attribute] = dashboard["meta"][attribute]
4950

5051
put_dashboard_path = "/dashboards/db"
5152
return self.client.POST(put_dashboard_path, json=dashboard)

0 commit comments

Comments
 (0)