fix(dashboard): dashboard actions fail when bad component id exists in children array #22323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
There are edge cases where a bad / orphan component id can end up on a dashboard layout element's children array. When this happens it causes critical errors blocking critical dashboard behaviors. There is still some mystery around the workflow in the code that causes a bad id to get into the children array, but once it does it causes major issues. This PR makes the updateComponentParentsList runtime safe. Additional fixes may be required to resolve underlying cause of bad ids ending up in the dashboard data but that is out of scope for this PR.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
New unit tests added verify the code handles edge cases that were previously causing unhandled exceptions to be thrown.
The existing unit tests were untouched to ensure the already tested behavior did not change.
The affected code in this PR is run every time a dashboard is opened, edited, saved. Testing requires verification that general dashboard behaviors work as expected. The steps below are not exhaustive or prescriptive but represent some paths for general testing of these changes.
You can manually replicate the bad component id by injecting a bad id in https://github.com/apache/superset/blob/25114a7b97ca96341cdb2d5e6fceceddf6ebc3c4/superset-frontend/src/dashboard/actions/hydrate.js
Add:
after line 263
With the fix the above code insertion should not cause any errors of failures on dashboard behavior. If you add the above code in master without fix in this PR you should see various errors and odd behaviors as you interact, save, edit dashboards.
ADDITIONAL INFORMATION