Repository navigation
fix(dashboard): remap native filter scopes when duplicating charts on save as - #45038
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| scope = container.get("scope") | ||
| if isinstance(scope, dict) and isinstance(scope.get("excluded"), list): | ||
| remapped_excluded: list[int] = [] | ||
| for cid in scope["excluded"]: | ||
| try: | ||
| int_id = int(cid) | ||
| remapped_excluded.append(old_to_new_slice_ids.get(int_id, int_id)) | ||
| except (ValueError, TypeError): | ||
| remapped_excluded.append(cid) | ||
| scope["excluded"] = remapped_excluded |
There was a problem hiding this comment.
Suggestion: scope.selectedLayers encodes chart IDs in its keys, but this only remaps excluded. After duplication, layer-scoped filters still target the original chart IDs.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Incomplete implementation
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/daos/dashboard.py
**Line:** 568:577
**Comment:**
*Incomplete Implementation: `scope.selectedLayers` encodes chart IDs in its keys, but this only remaps `excluded`. After duplication, layer-scoped filters still target the original chart IDs.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Agreed—a filter scoped to a single layer keeps selectedLayers entries like chart-<old_id>-layer-0, so on the copied dashboard the layer scope is looked up under the original chart ID and the cloned chart gets no layer-specific scope, so the filter can hit every layer of the copy. Should the chart-ID part of each selectedLayers entry be remapped (keeping the layer index) alongside excluded and chartsInScope?
There was a problem hiding this comment.
Yes. If scope.selectedLayers uses keys such as chart-<old_id>-layer-0, those keys need the same chart-ID remapping; otherwise the copied filter’s layer selection remains associated with the original chart. Remap only the chart-ID portion and preserve the layer suffix, leaving unrecognized or unmapped entries unchanged. Add a test asserting that chart-<old_id>-layer-0 becomes chart-<new_id>-layer-0. This complements the existing excluded and chartsInScope remapping.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of d7e799a.
Added _remap_selected_layers, which extracts chart IDs from selectedLayers keys, maps them to the duplicated chart IDs, and preserves each key’s suffix.
If that's not right, unresolve this thread and CodeAnt will leave it open.
| if isinstance(metadata.get("native_filter_configuration"), list): | ||
| for native_filter in metadata["native_filter_configuration"]: | ||
| cls._remap_filter_scope(native_filter, old_to_new_slice_ids) |
There was a problem hiding this comment.
Suggestion: chart_customization_config also stores scope references, but this remaps only native filters. Customization exclusions and cached targets can therefore still point to original charts after duplication.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Incomplete implementation
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/daos/dashboard.py
**Line:** 612:614
**Comment:**
*Incomplete Implementation: `chart_customization_config` also stores scope references, but this remaps only native filters. Customization exclusions and cached targets can therefore still point to original charts after duplication.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Agreed—chart_customization_config uses the same scope.excluded/chartsInScope shape and is skipped by _remap_filter_scopes. A Dynamic Group By control that excludes chart B still lists B's original ID after Save As, so scope recomputation includes the copied B and the control changes it unexpectedly. Should the customization entries go through _remap_filter_scope as well?
There was a problem hiding this comment.
Yes. Since chart_customization_config entries use the same scope.excluded and chartsInScope fields, they should also be passed through _remap_filter_scope during duplication. Otherwise, those references remain pointed at the original charts, and scope recomputation can behave differently on the copied dashboard. Handle the configuration’s entries defensively, as with native filters, and add a test for a customization that excludes a duplicated chart. The omission is a valid gap in the current remapping.
There was a problem hiding this comment.
✅ CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of d7e799a.
The metadata traversal now applies _remap_filter_scope to entries in both native_filter_configuration and chart_customization_config, remapping their exclusions, selected layers, and chart-scope references.
If that's not right, unresolve this thread and CodeAnt will leave it open.
CodeAnt PR Risk: Low Risk
Assessed commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45038 +/- ##
===========================================
+ Coverage 56.16% 83.36% +27.20%
===========================================
Files 3040 3040
Lines 198655 198734 +79
Branches 46360 46383 +23
===========================================
+ Hits 111565 165681 +54116
+ Misses 86024 29823 -56201
- Partials 1066 3230 +2164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @sadpandajoe, Addressed both scope remapping gaps in commits
Added regression unit tests in |
| ] | ||
|
|
||
|
|
||
| def test_copy_dashboard_does_not_double_remap_overlapping_ids( |
There was a problem hiding this comment.
This test is named and commented as covering overlapping IDs, but the clones get fresh primary keys while both originals still exist, so no new ID ever equals an old mapping key. A regression that remapped twice would still pass these assertions. Could you drive a mapping like {1: 2, 2: 3} through set_dash_metadata (with chartsInScope=[1, 2], excluded=[1], selectedLayers=["chart-1-layer-0"]) and assert [2, 3], [2] and "chart-2-layer-0"?
There was a problem hiding this comment.
Added in commit 0786da887f:
test_set_dash_metadata_does_not_double_remap_overlapping_ids drives {1: 2, 2: 3} through set_dash_metadata with chartsInScope=[1, 2], excluded=[1], and selectedLayers=["chart-1-layer-0"]. It asserts that the saved metadata produces [2, 3], [2], and ["chart-2-layer-0"], verifying that single-pass atomic remapping is preserved and no chained remapping (1 -> 2 -> 3) occurs.
|
Pushed commit The test feeds overlapping mapping All 20 unit tests in @coderabbitai review |
| for key in ("native_filter_configuration", "chart_customization_config"): | ||
| if isinstance(metadata.get(key), list): | ||
| for item in metadata[key]: | ||
| cls._remap_filter_scope(item, old_to_new_slice_ids) |
There was a problem hiding this comment.
Legacy chart_customization_config entries carry their target in a top-level chartId (no type key), and migrateChartCustomization rebuilds chartsInScope from it on load. Nothing here remaps that field, so after Save As with duplicated charts a legacy {chartId: 10, customization: {...}} keeps pointing at the original chart 10 even though the copy only contains the new chart. The control then won't show for the copied chart. Should _remap_filter_scope also map chartId for these items?
There was a problem hiding this comment.
Good catch @sadpandajoe! Updated DashboardDAO._remap_filter_scope in commit d07e3bbbed so legacy chart_customization_config entries with a top-level chartId (with a not isinstance(..., bool) guard) are remapped through old_to_new_slice_ids alongside scope and chartsInScope. Also added legacy chartId coverage in test_issue_44983_consolidated_evidence_gate and test_set_dash_metadata_does_not_double_remap_overlapping_ids.
| f"chart-{copied_c1_id}-layer-0" | ||
| ] | ||
|
|
||
| def test_set_dash_metadata_does_not_double_remap_overlapping_ids( |
There was a problem hiding this comment.
Only one blank line separates this def from the previous test, and the file ends with an extra blank line. The pre-commit job fails on ruff-format and fix end of files for this PR. Could you run pre-commit run --files superset/daos/dashboard.py tests/unit_tests/dao/dashboard_test.py and push the result?
There was a problem hiding this comment.
Fixed in commit d07e3bbbed. Restored the two-blank-line separation before test_set_dash_metadata_does_not_double_remap_overlapping_ids, normalized the trailing newline, and verified ruff check and ruff format pass cleanly on both files.
There was a problem hiding this comment.
The pre-commit (current) job is still red on this head: auto-walrus rewrites the re.match assignment and if in _remap_layer_key, and ruff-format reformats both files (the _remap_selected_layers list comprehension in superset/daos/dashboard.py and the end of the new overlap test here), so the check keeps failing. Could you run pre-commit run --files superset/daos/dashboard.py tests/unit_tests/dao/dashboard_test.py and push the result?
There was a problem hiding this comment.
Applied auto-walrus syntax in _remap_layer_key and formatted both superset/daos/dashboard.py and tests/unit_tests/dao/dashboard_test.py with ruff-format in commit efe8edf.
|
Thanks for the follow-up review @sadpandajoe! I have pushed commit
|
… save as (apache#44983) When saving a dashboard as a copy with duplicated charts (duplicate_slices=True), chartsInScope and scope.excluded within native filters metadata continued to reference the old chart slice IDs, breaking filter scope bindings on the new dashboard. This change: 1. Implements _remap_filter_scopes, _remap_filter_scope, _remap_chart_configuration, _remap_selected_layers, and _remap_slice_id_list in DashboardDAO (superset/daos/dashboard.py). 2. Remaps chart IDs in chartsInScope, scope.excluded, selectedLayers, and legacy chartId across native_filter_configuration, global_chart_configuration, and chart_configuration using old_to_new_slice_ids. 3. Handles dividers and non-dictionary elements gracefully without raising errors. 4. Adds comprehensive unit test suites in tests/unit_tests/dao/dashboard_test.py. Fixes apache#44983
efe8edf to
e7f230b
Compare
Rebase & Verification UpdateThe PR branch has been rebased cleanly onto latest
The PR is up to date and ready for review. |
SUMMARY
Fixes #44983.
When saving a dashboard as a copy with duplicated charts (duplicate_slices=True), chartsInScope and scope.excluded within native filters metadata continued to reference the old chart slice IDs, breaking filter scope bindings on the new dashboard.
This change:
TESTING INSTRUCTIONS
Run the dashboard DAO unit tests:
pytest tests/unit_tests/dao/dashboard_test.py
All tests pass, confirming correct slice ID remapping for single and multi-filter dashboards.
ADDITIONAL INFORMATION