From 5dacd2edff8969cdec38ca6a94a96e33246e5714 Mon Sep 17 00:00:00 2001 From: Roberto Jimenez Sanchez Date: Wed, 3 Dec 2025 08:19:58 +0100 Subject: [PATCH] fix: use folder UID instead of name for tree keying - Change AddUnstructured to use item.GetUID() instead of item.GetName() - This fixes the mismatch where GetFolder() returns UID but tree was keyed by name - Folders in Grafana are identified by UID, so tree should be keyed by UID --- pkg/registry/apis/provisioning/jobs/export/resources.go | 7 ++++++- pkg/registry/apis/provisioning/resources/tree.go | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/registry/apis/provisioning/jobs/export/resources.go b/pkg/registry/apis/provisioning/jobs/export/resources.go index 30d69cd3893..535649f58b5 100644 --- a/pkg/registry/apis/provisioning/jobs/export/resources.go +++ b/pkg/registry/apis/provisioning/jobs/export/resources.go @@ -356,7 +356,12 @@ func computeExportPath(basePath string, meta utils.GrafanaMetaAccessor, tree res if resourceFolder != "" { // Get the folder path from the unmanaged tree (rootFolder is empty string for unmanaged tree) fid, ok := tree.DirPath(resourceFolder, "") - if ok && fid.Path != "" { + if !ok { + // Folder not found in tree - this shouldn't happen for unmanaged folders + // but if it does, we'll just use the base path + return exportPath + } + if fid.Path != "" { if exportPath != "" { exportPath = safepath.Join(exportPath, fid.Path) } else { diff --git a/pkg/registry/apis/provisioning/resources/tree.go b/pkg/registry/apis/provisioning/resources/tree.go index 0fc25fd15ca..5f59d3b821d 100644 --- a/pkg/registry/apis/provisioning/resources/tree.go +++ b/pkg/registry/apis/provisioning/resources/tree.go @@ -145,9 +145,12 @@ func (t *folderTree) AddUnstructured(item *unstructured.Unstructured) error { return fmt.Errorf("extract meta accessor: %w", err) } + // Use UID as the identifier since GetFolder() returns UID + // In Grafana's folder API, folders are identified by UID + folderUID := string(item.GetUID()) folder := Folder{ Title: meta.FindTitle(item.GetName()), - ID: item.GetName(), + ID: folderUID, } t.mu.Lock() defer t.mu.Unlock()