fix(chart API): apply dashboard filters by live scope, not stale chartsInScope#41214
fix(chart API): apply dashboard filters by live scope, not stale chartsInScope#41214Vitor-Avila wants to merge 1 commit into
Conversation
Code Review Agent Run #7dda51Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
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
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:
|
There was a problem hiding this comment.
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 persistedchartsInScope). - Add/adjust unit tests to cover regressions where
chartsInScopeis stale or empty butscopeis 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. |
| @@ -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 | |||
|
The observation is correct. By removing the superset/charts/data/dashboard_filter_context.py |
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 onchartsInScope, which is recomputed on every load, so could be stale. This PR updates the logic to rely onscope(rootPath/excluded) instead.I believe the actual root-cause for stale/incorrect
chartsInScopevalues 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:
chartsInScope.GETto/api/v1/chart/<id>/data/?filters_dashboard_id=<id>and confirm the query/data also includes the filter.ADDITIONAL INFORMATION