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()