Skip to content

fix(chart API): apply dashboard filters by live scope, not stale chartsInScope#41214

Open
Vitor-Avila wants to merge 1 commit into
masterfrom
fix/dashboard-filter-scope-stale-chartsinscope
Open

fix(chart API): apply dashboard filters by live scope, not stale chartsInScope#41214
Vitor-Avila wants to merge 1 commit into
masterfrom
fix/dashboard-filter-scope-stale-chartsinscope

Conversation

@Vitor-Avila

Copy link
Copy Markdown
Contributor

SUMMARY

When a chart's data/query is fetched with filters_dashboard_id (GET /api/v1/chart/<id>/data/?filters_dashboard_id=<id>), some dashboard filters were not properly applied. The current logic was relying on chartsInScope, which is recomputed on every load, so could be stale. This PR updates the logic to rely on scope (rootPath / excluded) instead.

I believe the actual root-cause for stale/incorrect chartsInScope values might have been already fixed (for example with #38171) but this PR ensures dashboards in this state also work properly with this API endpoint.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No UI changes.

TESTING INSTRUCTIONS

Test coverage updated. For manual testing:

  1. Add a chart to a dashboard with default filter.
  2. Make sure the filter is scoped to all charts, but intentionally remove the chart ID from chartsInScope.
  3. Validate the filter still works properly via the UI.
  4. Send a GET to /api/v1/chart/<id>/data/?filters_dashboard_id=<id> and confirm the query/data also includes the filter.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot Bot added api:charts Related to the REST endpoints of charts dashboard:native-filters Related to the native filters of the Dashboard labels Jun 18, 2026
@bito-code-review

bito-code-review Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #7dda51

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 494af99..494af99
    • superset/charts/data/dashboard_filter_context.py
    • tests/unit_tests/charts/test_dashboard_filter_context.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

@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 494af99
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a34785fc8b6d20008978636
😎 Deploy Preview https://deploy-preview-41214--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.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.75%. Comparing base (76e2418) to head (494af99).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
superset/charts/data/dashboard_filter_context.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41214      +/-   ##
==========================================
- Coverage   64.33%   63.75%   -0.58%     
==========================================
  Files        2651     2651              
  Lines      144784   144784              
  Branches    33406    33405       -1     
==========================================
- Hits        93140    92304     -836     
- Misses      49976    50809     +833     
- Partials     1668     1671       +3     
Flag Coverage Δ
hive 39.32% <0.00%> (ø)
mysql 58.05% <0.00%> (+<0.01%) ⬆️
postgres 58.12% <0.00%> (-0.01%) ⬇️
presto 40.91% <0.00%> (+<0.01%) ⬆️
python 58.33% <0.00%> (-1.24%) ⬇️
sqlite 57.78% <0.00%> (+<0.01%) ⬆️
unit ?

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

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes how the chart data API applies dashboard native filters when filters_dashboard_id is provided, switching filter scoping logic to rely on scope.rootPath / scope.excluded (the authoritative source) instead of the persisted chartsInScope denormalized cache, which can be stale.

Changes:

  • Update backend filter scoping to compute in-scope charts exclusively from scope + dashboard layout (and not from persisted chartsInScope).
  • Add/adjust unit tests to cover regressions where chartsInScope is stale or empty but scope is correct.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
superset/charts/data/dashboard_filter_context.py Changes _is_filter_in_scope_for_chart to use scope.rootPath/excluded rather than chartsInScope when deciding filter applicability.
tests/unit_tests/charts/test_dashboard_filter_context.py Updates tests to assert that stale/empty chartsInScope does not prevent filters from applying when scope includes the chart.

Comment on lines 88 to +101
@@ -107,8 +98,7 @@ def _is_filter_in_scope_for_chart(

# If the chart doesn't exist in the dashboard layout, treat it as a
# root-level chart.
else:
return "ROOT_ID" in root_path
return "ROOT_ID" in root_path
@bito-code-review

Copy link
Copy Markdown
Contributor

The observation is correct. By removing the chartsInScope check entirely, the function now relies solely on the scope dictionary. If scope is missing or malformed (e.g., not a dictionary), scope.get("rootPath", []) defaults to an empty list, causing the filter to be incorrectly excluded for all charts. Using chartsInScope as a fallback when scope is missing or invalid would preserve backward compatibility for older dashboard metadata while still allowing the intended fix for stale cache issues.

superset/charts/data/dashboard_filter_context.py

scope = filter_config.get("scope")
    if isinstance(scope, dict):
        root_path: list[str] = scope.get("rootPath", [])
        excluded: list[int] = scope.get("excluded", [])
    else:
        # Fallback to chartsInScope if scope is missing or invalid
        charts_in_scope = filter_config.get("chartsInScope")
        if isinstance(charts_in_scope, list):
            return chart_id in charts_in_scope
        return False

@eschutho eschutho self-assigned this Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:charts Related to the REST endpoints of charts dashboard:native-filters Related to the native filters of the Dashboard size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants