fix(dashboard): import with overwrite flag replaces charts instead of merging#36551
Conversation
… merging Fixes #22127 When importing dashboards via /api/v1/dashboard/import/ with overwrite=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. The fix mirrors the behavior of the assets import API (PR #22208) by: 1. Deleting all existing dashboard-slice relationships when overwrite=True before inserting the new ones from the import 2. Only querying existing relationships when overwrite=False (optimization) 3. Changing break to continue when encountering unknown chart UUIDs so all valid charts are processed instead of stopping at the first unknown one Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where importing dashboards with overwrite=True was merging chart associations instead of replacing them, preventing proper source control workflows. The fix aligns the dashboard import behavior with the assets import API by deleting existing chart relationships before inserting new ones when overwriting.
Key changes:
- Deletes all existing dashboard-slice relationships before inserting new ones when
overwrite=True - Changes
breaktocontinueto process all valid charts instead of stopping at first unknown UUID - Adds comprehensive unit tests verifying overwrite and merge behaviors
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| superset/commands/dashboard/importers/v1/init.py | Core fix: deletes existing chart relationships when overwriting and processes all valid chart UUIDs |
| tests/unit_tests/dashboards/commands/importers/v1/import_command_test.py | New test file with 4 tests covering overwrite replacement, merge behavior, and edge cases |
| if dashboard_chart_ids: | ||
| values = [ | ||
| {"dashboard_id": dashboard_id, "slice_id": chart_id} | ||
| for (dashboard_id, chart_id) in dashboard_chart_ids |
There was a problem hiding this comment.
The check if dashboard_chart_ids: guards against inserting an empty list, but the main issue is that when overwrite=True and the imported dashboard has no charts, the old relationships are deleted (line 189-193) but nothing prevents the code from attempting an insert with an empty list. While SQLAlchemy typically handles empty inserts gracefully, this check should be placed before both the delete operation and the insert to maintain consistency and avoid unnecessary database operations when there are no chart relationships to manage.
| expected_number_of_dashboards = len(dashboards_config_1) | ||
| expected_number_of_charts = len(charts_config_1) |
There was a problem hiding this comment.
The variable names expected_number_of_dashboards and expected_number_of_charts are misleading. These represent the count of dashboard configurations and chart configurations in the import, not necessarily the expected number after import (especially for charts, which counts chart-dashboard associations in this test, not unique charts). Consider renaming to import_config_dashboard_count and import_config_chart_count, or add assertions that clarify what these values represent in the context of the test.
… merging (#36551) Co-authored-by: Claude <noreply@anthropic.com>
… merging (apache#36551) Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit 52c711b)
Cover remaining 6.1 features across existing and new pages: MCP server: - Add MCP_PARSE_REQUEST_ENABLED to configuration reference - Add Audit Events section (MCP tool calls appear in Action Log) - Add Tool Pagination section documenting cursor-based pagination (#37674) Using AI with Superset: - Expand Available Tools Reference into categorized sections covering all new tools added in the MCP tool library expansion - Document preview-first workflow for generate_chart / update_chart Creating Your First Dashboard: - AG Grid server-side column filters (#35683): filter types, AND/OR logic, pagination interaction - Time Shift for AG Grid Interactive Table (#37072) - Dynamic currency formatting via currency_code_column dataset field (#36416) - ECharts option editor in Explore for JSON overrides (#37868) - Table chart: export behavior with search filter active (#36281) - Dataset folders: organizing datasets into groups (#36239) - PWA file handler: opening CSV/XLS/Parquet from OS file manager (#36191) - Share database connection option when adding a new database (#37940) Exploring Data: - Dialect-aware Format SQL (applies selected database dialect) (#39393) - SQL Lab tips section and time range natural language expressions (consolidates content from batch 4 for master branch) Importing/Exporting: - Dashboard import overwrite behavior: charts are replaced not duplicated (#36551) - UUID in REST API POST responses for dataset/chart/dashboard (#37806) New pages: - docs/docs/using-superset/embedding.mdx: embedded SDK quick start, resolvePermalinkUrl callback (#36924), DISABLE_EMBEDDED_SUPERSET_LOGOUT feature flag (#37537), URL parameters, guest token security notes - docs/admin_docs/configuration/aws-iam.mdx: cross-account IAM authentication for Aurora and Redshift via STS AssumeRole (#37585), configuration reference, trust policy setup guide Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… merging (apache#36551) Co-authored-by: Claude <noreply@anthropic.com>
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