Skip to content

Conversation

@rusackas
Copy link
Member

SUMMARY

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.

Root Cause:
The ImportDashboardsCommand._import() method was only adding new chart relationships without removing existing ones when overwrite=True. In contrast, the ImportAssetsCommand._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:

  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 (performance 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 (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 implementation
  • tests/unit_tests/dashboards/commands/importers/v1/import_command_test.py - New tests for overwrite behavior

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - Backend API behavior change

TESTING INSTRUCTIONS

  1. Create a dashboard with 2 charts (chartA and chartB)
  2. Export the dashboard
  3. Extract the ZIP and remove chartB references:
    • Delete charts/chartB.yaml
    • Remove chartB from dashboards/dashboard.yaml position JSON
  4. Re-ZIP and import with overwrite=true:
    curl -X POST "http://localhost:8088/api/v1/dashboard/import/" \
      -H "Authorization: Bearer $TOKEN" \
      -F "formData=@modified_dashboard.zip;type=application/zip" \
      -F "overwrite=true"
  5. Before fix: Dashboard has both chartA and chartB (merged)
  6. After fix: Dashboard has only chartA (replaced)

ADDITIONAL INFORMATION

Related PRs:

Generated with Claude Code

… 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>
@dosubot dosubot bot added api Related to the REST API change:backend Requires changing the backend labels Dec 11, 2025
@github-actions github-actions bot removed the api Related to the REST API label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import dashboard/assets with overwrite flag does not replace dashboards

1 participant