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

[Question]: omitempty for slices results in a dirty dashboard state in Grafana v10.4.1 #637

Open
olehholovko-stripe opened this issue Feb 20, 2025 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@olehholovko-stripe
Copy link

What do you need?

Hi!

I'm using Golang structs to json.Unmarshal a Grafana v10.4.1 dashboard JSON, make some changes to the dashboard, json.Marshal it and upload the new dashboard back to Grafana. I noticed that Grafana v10.4.1 keeps empty lists in the JSON as is (e.g. "links": []). However, if I do json.Unmarshal into a variable of type Dashboard and then json.Marshal, empty lists are no longer present in the JSON (for example, Dashboard.Links or Dashboard.Tags, but also applicable to any slices in other structs used in Dashboard). This is because of the omitempty in the json tags.

Why it's problematic? If I then upload the JSON to Grafana and refresh a dashboard UI, the dashboard is in a dirty state: clicking on Save dashboard button shows multiple outstanding changes, primarily to add those empty lists back to the JSON.

Are there specific reasons to have omitempty for slices and is it possible to remove them?

Thanks,
Oleh

@olehholovko-stripe olehholovko-stripe added help wanted Extra attention is needed question Further information is requested labels Feb 20, 2025
@spinillos
Copy link
Member

The omitempty is added when the schema defines these fields as optional. Do you have a minimal example to test it and try to find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants