Skip to content

Commit 51e70da

Browse files
committed
Improve get_dashboard_versions to collect all pages
... to avoid missing history.
1 parent e35c644 commit 51e70da

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ in progress
77
===========
88
- Fixed ``grafana-wtf log`` subcommand for Grafana >= 11.6.0.
99
- Fixed compatibility with Grafana >= 12.x.
10+
- Improved ``get_dashboard_versions`` to collect all pages
11+
to avoid missing history. Thanks, @coderabbitai.
1012

1113
2025-07-28 0.23.2
1214
=================

grafana_wtf/core.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,21 @@ def search_items(self, expression, items, results):
464464
def get_dashboard_versions(self, dashboard_id):
465465
# https://grafana.com/docs/http_api/dashboard_versions/
466466
get_dashboard_versions_path = "/dashboards/id/%s/versions" % dashboard_id
467-
data = self.grafana.dashboard.client.GET(get_dashboard_versions_path)
468-
if "continueToken" in data:
469-
return data["versions"]
470-
else:
471-
return data
467+
results = []
468+
params = {}
469+
while True:
470+
data = self.grafana.dashboard.client.GET(get_dashboard_versions_path, params=params)
471+
# Older Grafana returned a plain list.
472+
if isinstance(data, list):
473+
results.extend(data)
474+
break
475+
# Newer Grafana returns a dict with `versions` and optional `continueToken`.
476+
results.extend(data.get("versions", []))
477+
token = data.get("continueToken")
478+
if not token:
479+
break
480+
params = {"continueToken": token}
481+
return results
472482

473483
def explore_datasources(self):
474484
# Prepare indexes, mapping dashboards by uid, datasources by name

0 commit comments

Comments
 (0)