Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restoring library elements that have more than one folder #199

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

antifuchs
Copy link
Contributor

If multiple folders are present on a library element (e.g. if used in multiple dashboards in different folders), the API returns multiple folder ID responses. Handle that by recreating the element with the first folder.

Also, switch from using folderId to folderUid (folderId has been deprecated since grafana v9).

I unfortunately couldn't get my editor to not re-format the file with black in the hurry I was in today. If this is undesired, let me know and I'll fix it later.

If multiple folders are present on a library element (e.g. if used in
multiple dashboards in different folders), the API returns multiple
folder ID responses. Handle that by recreating the element with the
first folder.

Also, switch from using folderId to folderUid (folderId has been
deprecated since grafana v9).
@ysde
Copy link
Owner

ysde commented Feb 24, 2023

Hi @antifuchs

thanks for the PR

What do you mean by that "re-format the file with black"

Thank you

folder_id_response = get_folder(
folder_uid, grafana_url, http_post_headers, verify_ssl, client_cert, debug
)[1]
if isinstance(folder_id_response, list):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test len(folder_id_response) here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't think so: there is always at least one, probably more than one in the array case.

I don't know what to do if the grafana API started returning arrays that didn't contain any folders at all.

@ysde ysde merged commit cdfd6b7 into ysde:master Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants