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

Dashboards: It always detect changes when saving an existing dashboard #76116

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

ivanortegaalba
Copy link
Contributor

@ivanortegaalba ivanortegaalba commented Oct 6, 2023

Problem
No matter if you make changes in a dashboard, it always contains changes.

The issue seems to be the mutation of the values of the model that they still point to the original object passed as data to DashboardModel. So, during the initDashboard, the this.originalDashboard is modified because the assigned object to the different Model props shares the object reference.

Solution
Clone the original object stored in originalDashboard to avoid this issue in the future by accidental mutations.

How to test it:

  1. Go to any non-empty dashboard. For example this one: https://play.grafana.org/d/Ib-GkgRVk/graphite3a-wikimedia-com-metrics?orgId=1
  2. Save without making any changes to do the needed mutations
  3. Reload and save again. The same change is applied.

@ivanortegaalba ivanortegaalba requested a review from a team as a code owner October 6, 2023 10:55
@ivanortegaalba ivanortegaalba requested review from dprokop and polibb and removed request for a team October 6, 2023 10:55
@ivanortegaalba ivanortegaalba marked this pull request as draft October 6, 2023 10:55
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.2.x milestone Oct 6, 2023
@ivanortegaalba ivanortegaalba marked this pull request as ready for review October 6, 2023 11:37
@grafana-delivery-bot
Copy link
Contributor

Hello @ivanortegaalba!
Backport pull requests need to be either:

  • Pull requests which address bugs,
  • Urgent fixes which need product approval, in order to get merged,
  • Docs changes.

Please, if the current pull request addresses a bug fix, label it with the type/bug label.
If it already has the product approval, please add the product-approved label. For docs changes, please add the type/docs label.
If the pull request modifies CI behaviour, please add the type/ci label.
If none of the above applies, please consider removing the backport label and target the next major/minor release.
Thanks!

@ivanortegaalba ivanortegaalba changed the title Fix: Dashboard always has changes when saving Dashboards: It always detect changes when saving an existing dashboard Oct 6, 2023
@ivanortegaalba ivanortegaalba added backport v9.5.x Bot will automatically open backport PR and removed backport v8.4.x Mark PR for automatic backport to v8.4.x labels Oct 6, 2023
@grafana grafana deleted a comment from grafana-delivery-bot bot Oct 6, 2023
@ivanortegaalba ivanortegaalba requested review from torkelo, a team, axelavargas and polibb and removed request for a team October 6, 2023 11:48
Copy link
Member

@torkelo torkelo left a comment

Choose a reason for hiding this comment

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

tried opening a bunch of old dashboards and seems to not crash :)

@ivanortegaalba ivanortegaalba merged commit 1a96f37 into main Oct 6, 2023
35 checks passed
@ivanortegaalba ivanortegaalba deleted the fix-always-changes branch October 6, 2023 12:32
@grafana-delivery-bot
Copy link
Contributor

The backport to v9.5.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-76116-to-v9.5.x origin/v9.5.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 1a96f3742f84284e64f48fb52f0ef6a78dad1ac0
# When the conflicts are resolved, stage and commit the changes
git add . && git cherry-pick --continue

If you have the GitHub CLI installed:

# Push the branch to GitHub:
git push --set-upstream origin backport-76116-to-v9.5.x
# Create the PR body template
PR_BODY=$(gh pr view 76116 --json body --template 'Backport 1a96f3742f84284e64f48fb52f0ef6a78dad1ac0 from #76116{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[v9.5.x] Dashboards: It always detect changes when saving an existing dashboard " --body-file - --label "type/bug" --label "area/frontend" --label "add to changelog" --label "backport" --base v9.5.x --milestone 9.5.x --web

Or, if you don't have the GitHub CLI installed (we recommend you install it!):

# Push the branch to GitHub:
git push --set-upstream origin backport-76116-to-v9.5.x

# Create a pull request where the `base` branch is `v9.5.x` and the `compare`/`head` branch is `backport-76116-to-v9.5.x`.

# Remove the local backport branch
git switch main
git branch -D backport-76116-to-v9.5.x

@grafana-delivery-bot grafana-delivery-bot bot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Oct 6, 2023
@grafana-delivery-bot
Copy link
Contributor

The backport to v10.1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-76116-to-v10.1.x origin/v10.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 1a96f3742f84284e64f48fb52f0ef6a78dad1ac0
# When the conflicts are resolved, stage and commit the changes
git add . && git cherry-pick --continue

If you have the GitHub CLI installed:

# Push the branch to GitHub:
git push --set-upstream origin backport-76116-to-v10.1.x
# Create the PR body template
PR_BODY=$(gh pr view 76116 --json body --template 'Backport 1a96f3742f84284e64f48fb52f0ef6a78dad1ac0 from #76116{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[v10.1.x] Dashboards: It always detect changes when saving an existing dashboard " --body-file - --label "type/bug" --label "area/frontend" --label "add to changelog" --label "backport" --base v10.1.x --milestone 10.1.x --web

Or, if you don't have the GitHub CLI installed (we recommend you install it!):

# Push the branch to GitHub:
git push --set-upstream origin backport-76116-to-v10.1.x

# Create a pull request where the `base` branch is `v10.1.x` and the `compare`/`head` branch is `backport-76116-to-v10.1.x`.

# Remove the local backport branch
git switch main
git branch -D backport-76116-to-v10.1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend backport v9.5.x Bot will automatically open backport PR backport v10.1.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. type/bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants