fix(dashboard): import with overwrite flag replaces charts instead of merging #36551
+245
−11
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
Fixes #22127
When importing dashboards via
/api/v1/dashboard/import/withoverwrite=True, the dashboard's chart associations were being merged with existing charts instead of being replaced. This made it impossible to use the import API for proper source control workflows where the imported dashboard should exactly match the import file.Root Cause:
The
ImportDashboardsCommand._import()method was only adding new chart relationships without removing existing ones whenoverwrite=True. In contrast, theImportAssetsCommand._import()method (from PR #22208) correctly deletes existing relationships before inserting new ones.The Fix:
This PR mirrors the behavior of the assets import API by:
overwrite=Truebefore inserting the new ones from the importoverwrite=False(performance optimization)breaktocontinuewhen encountering unknown chart UUIDs so all valid charts are processed instead of stopping at the first unknown one (also identified in PR fix(dashboard): Dashboard import commands not correctly replacing charts #25102 review)Files Changed:
superset/commands/dashboard/importers/v1/__init__.py- Core fix implementationtests/unit_tests/dashboards/commands/importers/v1/import_command_test.py- New tests for overwrite behaviorBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend API behavior change
TESTING INSTRUCTIONS
charts/chartB.yamldashboards/dashboard.yamlposition JSONoverwrite=true:ADDITIONAL INFORMATION
Related PRs:
Generated with Claude Code