rusackas opened a new pull request, #36551:
URL: https://github.com/apache/superset/pull/36551
### 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 #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`:
```bash
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
- [x] Has associated issue: #22127
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
**Related PRs:**
- #22208 - Original fix for assets API (merged)
- #23489 - Previous attempt at this fix (closed)
- #25102 - Another attempt at this fix (closed draft)
Generated with [Claude Code](https://claude.ai/code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]