Skip to content

fix(dashboard-import): remap chartsInScope on import (#26338)#40140

Merged
rusackas merged 4 commits into
masterfrom
tdd/issue-26338-chartsinscope-import
May 20, 2026
Merged

fix(dashboard-import): remap chartsInScope on import (#26338)#40140
rusackas merged 4 commits into
masterfrom
tdd/issue-26338-chartsinscope-import

Conversation

@rusackas
Copy link
Copy Markdown
Member

@rusackas rusackas commented May 15, 2026

SUMMARY

Closes #26338.

chartsInScope is a denormalized cache of the charts a native filter (or cross-filter) currently applies to. update_id_refs was remapping the rest of the scope contract (scope.excluded, position chart IDs, native filter dataset IDs, etc.) but leaving chartsInScope untouched. The imported dashboard's filtersInScope / filtersOutScope computation then operated on stale source-environment IDs — filters ended up applied to the wrong charts (or none at all), exactly as #26338 reports.

This PR:

  1. Adds a chartsInScope remap pass in superset/commands/dashboard/importers/v1/utils.py for both:

    • Each native_filter_configuration entry's chartsInScope
    • Each chart_configuration[*].crossFilters.chartsInScope (the cross-filter version)

    Mirrors the existing scope.excluded handling. Drops unresolvable IDs rather than passing them through, matching the established convention.

  2. Locks in regression tests (added in the PR's earlier commit):

    • test_update_id_refs_remaps_charts_in_scope — native filter case
    • test_update_id_refs_remaps_cross_filter_charts_in_scope — cross-filter case

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend ID-remapping change. CI on the test commit (before this fix) showed the bug verbatim:

FAILED test_update_id_refs_remaps_charts_in_scope - assert [101, 102, 103] == [1, 2]
FAILED test_update_id_refs_remaps_cross_filter_charts_in_scope - assert [101, 102, 103] == [1, 2]

CI on this fix commit should green.

TESTING INSTRUCTIONS

pytest tests/unit_tests/dashboards/commands/importers/v1/utils_test.py::test_update_id_refs_remaps_charts_in_scope -v
pytest tests/unit_tests/dashboards/commands/importers/v1/utils_test.py::test_update_id_refs_remaps_cross_filter_charts_in_scope -v

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

@dosubot dosubot Bot added closes-issue dashboard:import Related to importing dashboards labels May 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.18%. Comparing base (46b2d7d) to head (e2ba073).

Files with missing lines Patch % Lines
superset/commands/dashboard/importers/v1/utils.py 40.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40140      +/-   ##
==========================================
- Coverage   64.18%   64.18%   -0.01%     
==========================================
  Files        2591     2591              
  Lines      138446   138455       +9     
  Branches    32116    32118       +2     
==========================================
+ Hits        88868    88870       +2     
- Misses      48047    48053       +6     
- Partials     1531     1532       +1     
Flag Coverage Δ
hive 39.41% <20.00%> (-0.01%) ⬇️
mysql 59.06% <40.00%> (-0.01%) ⬇️
postgres 59.14% <40.00%> (-0.01%) ⬇️
presto 41.09% <20.00%> (-0.01%) ⬇️
python 60.57% <40.00%> (-0.01%) ⬇️
sqlite 58.78% <40.00%> (-0.01%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
Comment thread tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
Copy link
Copy Markdown
Contributor

@bito-code-review bito-code-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #c144e5

Actionable Suggestions - 1
  • tests/unit_tests/dashboards/commands/importers/v1/utils_test.py - 1
Review Details
  • Files reviewed - 1 · Commit Range: cdab809..cdab809
    • tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread tests/unit_tests/dashboards/commands/importers/v1/utils_test.py
@pull-request-size pull-request-size Bot added size/L and removed size/M labels May 15, 2026
@rusackas rusackas changed the title test(dashboard-import): pin chartsInScope ID remapping (#26338) fix(dashboard-import): remap chartsInScope on import (#26338) May 15, 2026
@rusackas rusackas requested a review from sadpandajoe May 15, 2026 05:17
Copy link
Copy Markdown
Contributor

@bito-code-review bito-code-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #5da3f2

Actionable Suggestions - 1
  • superset/commands/dashboard/importers/v1/utils.py - 1
    • Semantic Duplication in chartsInScope Handling · Line 154-158
Review Details
  • Files reviewed - 1 · Commit Range: cdab809..31a7ebe
    • superset/commands/dashboard/importers/v1/utils.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/commands/dashboard/importers/v1/utils.py Outdated
rusackas pushed a commit that referenced this pull request May 15, 2026
Per bito review on PR #40140: the native-filter and cross-filter blocks
were running identical chartsInScope remap logic. Pull the shared shape
into a single private helper so the two callsites can't drift.

No behavior change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 15, 2026

Code Review Agent Run #ad0d84

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 31a7ebe..1b9ac54
    • superset/commands/dashboard/importers/v1/utils.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/commands/dashboard/importers/v1/utils.py
@rusackas rusackas requested a review from aminghadersohi May 20, 2026 17:04
Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct and well-tested.

chartsInScope on native filters and cross-filter configs holds source-environment integer chart IDs after export. update_id_refs was already remapping every other ID-bearing field (scope.excluded, position chartIds, filter_scopes keys, etc.) but skipping chartsInScope, leaving stale source-env IDs that broke filtersInScope/filtersOutScope computation on the imported dashboard.

The _remap_charts_in_scope helper cleanly DRYs the remap across both surfaces (native filters and cross-filter configs), and drop-on-unresolvable matches the scope.excluded convention.

One NIT: the docstring in test_update_id_refs_remaps_charts_in_scope says the export converts chartsInScope to UUIDs (citing export_example.py:325), but the production ExportDashboardsCommand does not — it leaves integer IDs. The test fixture and the id_map usage are correct; only the comment is misleading.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit e2ba073
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a0e0b8222b4e40008877663
😎 Deploy Preview https://deploy-preview-40140--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

claude and others added 4 commits May 20, 2026 12:28
Closes #26338

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`chartsInScope` is a denormalized cache of the charts a filter currently
applies to. `update_id_refs` was remapping the rest of the scope contract
(`scope.excluded`, position chartIds, etc.) but leaving chartsInScope
untouched, so the imported dashboard's filtersInScope / filtersOutScope
computation operated on stale source-environment IDs — and filters ended
up applied to the wrong charts (or none at all).

Adds two remap passes mirroring the existing `scope.excluded` handling:

- One on each `native_filter_configuration` entry's `chartsInScope`.
- One on each `chart_configuration[*].crossFilters.chartsInScope` (the
  cross-filter version).

Drop unresolvable IDs rather than passing them through, matching the
existing convention for `scope.excluded`.

Companion regression tests added in this PR's earlier commit cover both
cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Per bito review on PR #40140: the native-filter and cross-filter blocks
were running identical chartsInScope remap logic. Pull the shared shape
into a single private helper so the two callsites can't drift.

No behavior change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Picks up the third call site flagged by @sadpandajoe — the per-chart
and native-filter chartsInScope branches were both routed through
_remap_charts_in_scope, but global_chart_configuration.chartsInScope
(which sits next to global_chart_configuration.scope.excluded) was
missed and would keep stale source-env IDs after import.

Adds a companion test
test_update_id_refs_remaps_global_chart_configuration_charts_in_scope
that builds the same source-env shape used in the other two regression
tests and asserts unresolved IDs drop while resolved IDs map across.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rusackas rusackas force-pushed the tdd/issue-26338-chartsinscope-import branch from 994834c to e2ba073 Compare May 20, 2026 19:29
@rusackas rusackas merged commit 4a9aecd into master May 20, 2026
65 checks passed
@rusackas rusackas deleted the tdd/issue-26338-chartsinscope-import branch May 20, 2026 20:41
@bito-code-review
Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chartsInScope references are not fixed during a Dashboard import

4 participants