Skip to content

fix(chart API): Consider time grain filters with the filters_dashboard_id param#41290

Merged
Vitor-Avila merged 2 commits into
masterfrom
fix/apply-time-grain-filters-dashboard-id
Jun 22, 2026
Merged

fix(chart API): Consider time grain filters with the filters_dashboard_id param#41290
Vitor-Avila merged 2 commits into
masterfrom
fix/apply-time-grain-filters-dashboard-id

Conversation

@Vitor-Avila

Copy link
Copy Markdown
Contributor

SUMMARY

The filters_dashboard_id URL param for the /api/v1/chart/<pk>/data API was not considering time grain filters applied in the dashboard. This PR fixes the issue.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No UI changes.

TESTING INSTRUCTIONS

Test coverage added. For manual testing:

  1. Create a line chart using the cleaned_sales_data dataset. Use order_date as the X-Axis with Time Grain set to Day, and any metric.
  2. Save this chart to a dashboard.
  3. Add a time grain filter to the dashboard, setting its default value to Year.
  4. Hit GET /api/v1/chart/{{ChartID}}/data?filters_dahsboard_id={{DashboardID}} and confirm the time grain applied is coming from the dashboard (not the chart's default value).

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 the api:charts Related to the REST endpoints of charts label Jun 22, 2026
@bito-code-review

bito-code-review Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #73fb3d

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/unit_tests/charts/test_chart_data_api.py - 1
    • Incomplete assertion coverage · Line 158-186
      Test docstring promises preservation of "timeGrain" when no dashboard grain is provided, but the assertion only checks `query["columns"][0]["timeGrain"]` — extras are not verified. If the implementation later corrupts `extras["time_grain_sqla"]` (e.g., setting it to None or an empty string), the test passes while breaking actual query behavior.
      Code suggestion
      --- a/tests/unit_tests/charts/test_chart_data_api.py
      +++ b/tests/unit_tests/charts/test_chart_data_api.py
       @@ -183,6 +183,7 @@ def test_apply_dashboard_filter_context_keeps_grain_when_no_grain_filter() -> Non
            )
       
            query = query_context_json["queries"][0]
            assert query["columns"][0]["timeGrain"] == "P1M"
      +    assert query["extras"]["time_grain_sqla"] == "P1M"
Review Details
  • Files reviewed - 2 · Commit Range: 0358411..0358411
    • superset/charts/data/dashboard_filter_context.py
    • tests/unit_tests/charts/test_chart_data_api.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 22, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

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

Comment on lines +339 to +340
if custom_time_grain := extra_form_data.get("time_grain_sqla"):
extras["time_grain_sqla"] = custom_time_grain

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.

Suggestion: The time-grain override is gated by a truthiness check, so a provided falsy value (for example an explicit empty/null-like value used to clear an existing grain) is ignored instead of being applied. This leaves stale chart-level grain values in extras/columns and makes dashboard overrides non-deterministic. Check for key presence (or is not None) rather than truthiness when deciding whether to apply the override. [incorrect condition logic]

Severity Level: Major ⚠️
- ❌ Dashboard time-grain clear operations silently fail.
- ⚠️ Chart and dashboard grains become inconsistent.
- ⚠️ Future falsy time-grain overrides behave non-deterministically.
Steps of Reproduction ✅
1. The chart data GET endpoint `/api/v1/chart/<pk>/data` builds `json_body` and, when
`filters_dashboard_id` is present, calls `get_dashboard_filter_context()` and then
`apply_dashboard_filter_context(json_body, efd)` at `superset/charts/data/api.py:14-29`.

2. `get_dashboard_filter_context()` in
`superset/charts/data/dashboard_filter_context.py:18-47` merges native filters'
`extra_form_data` into a single dict; if a time-grain native filter is configured to clear
the grain it can yield `extra_form_data={"time_grain_sqla": ""}` or `{"time_grain_sqla":
None}`.

3. `apply_dashboard_filter_context()` at
`superset/charts/data/dashboard_filter_context.py:64-86` executes `if custom_time_grain :=
extra_form_data.get("time_grain_sqla"):` (line 339 in the PR hunk); for a falsy override
like `""` or `None`, `custom_time_grain` is falsy so the block is skipped and
`extras["time_grain_sqla"]` is left at the prior chart-level value.

4. The resulting `query_context` (built later via
`_create_query_context_from_form(json_body)` in `superset/charts/data/api.py:38-40`) still
carries the old `extras["time_grain_sqla"]`, so any backend consumer (e.g.
`QueryObjectHelper.get_time_grain()` in `superset/models/helpers.py:2011-22` for charts
without adhoc x-axis) sees the stale grain and the dashboard attempt to clear or override
the grain is ignored.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/charts/data/dashboard_filter_context.py
**Line:** 339:340
**Comment:**
	*Incorrect Condition Logic: The time-grain override is gated by a truthiness check, so a provided falsy value (for example an explicit empty/null-like value used to clear an existing grain) is ignored instead of being applied. This leaves stale chart-level grain values in `extras`/columns and makes dashboard overrides non-deterministic. Check for key presence (or `is not None`) rather than truthiness when deciding whether to apply the override.

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 fix
👍 | 👎

Comment thread superset/charts/data/dashboard_filter_context.py Outdated
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.33%. Comparing base (403e11e) to head (f5dee3b).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
superset/charts/data/dashboard_filter_context.py 16.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41290      +/-   ##
==========================================
- Coverage   64.34%   64.33%   -0.02%     
==========================================
  Files        2653     2653              
  Lines      144989   145031      +42     
  Branches    33456    33463       +7     
==========================================
+ Hits        93295    93299       +4     
- Misses      50011    50046      +35     
- Partials     1683     1686       +3     
Flag Coverage Δ
hive 39.27% <16.66%> (-0.02%) ⬇️
mysql 58.00% <16.66%> (-0.03%) ⬇️
postgres 58.06% <16.66%> (-0.03%) ⬇️
presto 40.86% <16.66%> (-0.02%) ⬇️
python 59.50% <16.66%> (-0.03%) ⬇️
sqlite 57.72% <16.66%> (-0.03%) ⬇️
unit 100.00% <ø> (ø)

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

Fixes the /api/v1/chart/<pk>/data handling of the filters_dashboard_id parameter so that dashboard-applied time grain filters correctly override the chart’s query context (both in query.extras.time_grain_sqla and the X-Axis adhoc column’s timeGrain), aligning backend behavior with frontend normalization logic.

Changes:

  • Update apply_dashboard_filter_context to propagate time_grain_sqla into query["extras"] and into the BASE_AXIS column’s timeGrain.
  • Add unit tests to validate time grain override behavior (extras-only, X-Axis override, and no-grain-filter preservation).

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 Ensures dashboard time grain overrides are applied to query context extras and X-Axis column configuration.
tests/unit_tests/charts/test_chart_data_api.py Adds regression tests covering dashboard time grain override scenarios.

Comment thread superset/charts/data/dashboard_filter_context.py Outdated
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jun 22, 2026
@Vitor-Avila Vitor-Avila merged commit 3b46a5f into master Jun 22, 2026
62 checks passed
@Vitor-Avila Vitor-Avila deleted the fix/apply-time-grain-filters-dashboard-id branch June 22, 2026 23:01
@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

api:charts Related to the REST endpoints of charts size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants