Skip to content

fix(query): take chart time bounds from the temporal x-axis only - #46345

Open
sadpandajoe wants to merge 9 commits into
masterfrom
ultraset-temporal-range-filter-follows-chart-x-axis
Open

sadpandajoe wants to merge 9 commits into
masterfrom
ultraset-temporal-range-filter-follows-chart-x-axis

Conversation

@sadpandajoe

@sadpandajoe sadpandajoe commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Supersedes #39683.

Closes: #39683

On datasets with several datetime columns, a chart's time bounds could come from a column other than its x-axis, and a dashboard time range could overwrite filters on other datetime columns:

  1. get_time_range_from_filters (called by QueryObjectFactory to compute from_dttm/to_dttm) compared each TEMPORAL_RANGE filter's col only with the x-axis label and otherwise fell back to the first TEMPORAL_RANGE filter (fallback introduced in fix: the temporal x-axis results in a none time_range. #25429). A chart whose temporal x-axis had no range of its own took another column's range, and that range was then applied to the time column. A filter on the axis expression, or one whose col is an adhoc column, never matched.
  2. QueryContextFactory._apply_filters wrote time_range into every TEMPORAL_RANGE filter (since fix: Time Column on Generic X-axis #23021), so a range on a second datetime column was replaced by the dashboard time range, and a chart with no filter on its x-axis had the range applied to another column instead.

This PR:

  • Matches the x-axis to TEMPORAL_RANGE filters by label and then by expression, accepting plain strings and adhoc column dicts.
  • When the x-axis is a temporal column of the dataset and no filter targets it, uses no time range instead of another column's range. Charts with no x-axis, or with a non-temporal one (for example a bar chart by country), keep using the first temporal range, which a Time Column override relies on.
  • Applies the time range only to the TEMPORAL_RANGE filters on the chart's time column (granularity) or x-axis, by label or expression. A temporal x-axis with no such filter gets one carrying the range, unless a time column already carries it. When neither column is known, every TEMPORAL_RANGE filter takes the range as before.
  • Leaves _apply_granularity unchanged, so the dashboard Time Column override and the x-axis label it preserves keep working.

TESTING INSTRUCTIONS

  1. Use a dataset with two datetime columns, e.g. order_date and ship_date.
  2. Create a Bar Chart with x-axis order_date, a time filter order_date = No filter, and a second adhoc filter ship_date with a range that excludes some rows. Save it to a dashboard with a Time Range native filter and pick a range.
  3. In View query, the WHERE clause bounds order_date by the dashboard range and still applies the chart's own ship_date range. Before this change both columns were bounded by the dashboard range.
  4. Remove the order_date time filter from the chart: the query still bounds order_date by the dashboard range and keeps ship_date's own range. Before this change order_date was unbounded and ship_date took the dashboard range.
  5. Change the x-axis to a Custom SQL ship_date on a dataset whose main datetime column is order_date, with a ship_date time filter: both order_date and ship_date are bounded by the dashboard range.
  6. Change the x-axis to a categorical column (e.g. status) with only a time filter on order_date: that filter takes the dashboard range, as before.

ADDITIONAL INFORMATION

Behaviour change, recorded in UPDATING.md: a chart with a temporal x-axis but no TEMPORAL_RANGE on it no longer borrows another column's range, and a time range no longer overwrites filters on other datetime columns. It applies to the time column or x-axis filter and, for a temporal x-axis without one, is added as a filter on the x-axis. Existing tests that asserted the old overwrite were updated: the cache-values test in test_query_context_factory.py and the expected bar counts of five setups in test_drill_by_time_column.py (the February order shipped in July now stays outside the chart's own ship_date range). The drill-by contract, that drill rows equal the clicked bar, still holds.

Notes:

  • A Custom SQL x-axis on a datetime column other than the dataset's main datetime column, with no time filter of its own, still receives the dashboard range on the main datetime column, not on the x-axis column. This is unchanged from before, because the granularity inference in _apply_granularity is left untouched.
  • Time-comparison offsets still pick the first TEMPORAL_RANGE filter (_get_temporal_column_for_filter); this PR does not change that path.

🤖 Generated with Claude Code

sadpandajoe and others added 3 commits November 19, 2026 00:13
When a chart's x-axis is a temporal column, the main time range comes only
from a TEMPORAL_RANGE filter on that axis, matched by label and then by
expression and comparing adhoc filter columns by label or expression. A
chart with no such filter no longer borrows another datetime column's range.
Charts without an x-axis, or with a non-temporal one, still use the first
temporal range.

With a known time column, a time range only replaces the TEMPORAL_RANGE
filter on that column, so filters on other datetime columns keep their own
ranges. Without one, every TEMPORAL_RANGE filter is still rewritten.

Fixes #39681

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ange-filter-follows-chart-x-axis

# Conflicts:
#	UPDATING.md
…lumn

Charts with a temporal x-axis and no Time Column carry no granularity, so
the time range still replaced the ranges of other datetime columns. An
expression x-axis on a datetime column other than the main one infers the
main datetime column as granularity, so its own range filter was skipped.

The time range now replaces the TEMPORAL_RANGE filters that target the time
column or the x-axis. A temporal x-axis without one gets a filter for the
range unless a time column already carries it. With neither column known,
every TEMPORAL_RANGE filter takes the range as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; time-range selection checks the chart axis before falling back to another temporal filter.
  • A regression test verifies that a Custom SQL axis uses the range on the datetime column it reads.

Assessed commit: 16716e0f0479

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.70115% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.94%. Comparing base (9969fe9) to head (16716e0).

Files with missing lines Patch % Lines
...c/components/Chart/DrillDetail/DrillDetailPane.tsx 75.00% 1 Missing ⚠️
superset/models/helpers.py 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46345      +/-   ##
==========================================
- Coverage   86.23%   85.94%   -0.30%     
==========================================
  Files        3146     3128      -18     
  Lines      220018   218233    -1785     
  Branches    52110    51250     -860     
==========================================
- Hits       189725   187551    -2174     
- Misses      26823    27213     +390     
+ Partials     3470     3469       -1     
Flag Coverage Δ
hive 33.63% <13.25%> (-0.01%) ⬇️
mysql 51.84% <69.87%> (+0.01%) ⬆️
postgres 51.86% <69.87%> (+0.01%) ⬆️
presto 35.33% <33.73%> (+<0.01%) ⬆️
python 88.82% <98.79%> (+0.01%) ⬆️
sqlite 51.56% <75.90%> (+0.01%) ⬆️
unit 84.39% <98.79%> (+0.02%) ⬆️

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.

@sadpandajoe
sadpandajoe requested a review from rusackas November 19, 2026 18:14
@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Nov 19, 2026
# Conflicts:
#	tests/unit_tests/common/test_time_range_utils.py
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Nov 20, 2026
@aminghadersohi
aminghadersohi self-requested a review November 21, 2026 16:39

@aminghadersohi aminghadersohi 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.

Time comparison on a temporal x-axis returns an empty series when the chart also filters another datetime column.

Comment on lines +533 to +534
else:
targets = temporal_filters

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.

Drill to Detail sends no x-axis column, so it reaches this branch and overwrites every TEMPORAL_RANGE filter, while the chart query keeps other datetime columns' own ranges; with a dashboard time range the detail rows no longer match the clicked bar.

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.

The dashboard time range case holds at 16716e0; a time cross-filter target's drill still diverges from the chart, see the new comment at query_context_factory.py:534.

…ts it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@aminghadersohi aminghadersohi 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.

Time comparison now shifts the x-axis range; the dashboard range still lands on the wrong column for Custom SQL x-axes, table groupbys and cross-filter targets.

Comment on lines +496 to +498
base_axes: list[Column] = get_base_axis_columns(
getattr(query_object, "columns", None)
)

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.

Table, pivot and box plot queries send a temporal groupby as BASE_AXIS with no x-axis, so the dashboard range now bounds that groupby column instead of the time filter column, while the table's totals query (no columns) still bounds ds: totals stop matching the rows.

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.

The rows and totals queries agree at 16716e0; the time comparison still takes the groupby as the time column, see the new comment at helpers.py:3880.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @sadpandajoe! I'm with @aminghadersohi on the open threads here, the cross-filter one especially. I'd love to see those sorted before this goes in, since it changes where dashboard time ranges land on a lot of charts.

sadpandajoe and others added 2 commits November 28, 2026 06:07
…uery

A time range replaces the TEMPORAL_RANGE filters on the chart's time column,
taken from the same inputs in every consumer:

- The chart's x-axis comes from the form data, not from any base-axis
  column, so a table, pivot table or box plot temporal groupby is not taken
  for it and its rows and totals query apply the range alike.
- A Custom SQL x-axis also matches the datetime columns its expression reads.
- A time x-axis cross-filter's range replaces ranges on the cross-filtered
  column only, not the target chart's x-axis.
- Without a filter on the time column, the range fills the chart's unbounded
  time filter before a filter is added on a temporal x-axis.
- Drill to Detail sends the chart's x-axis, so its rows keep the chart's other
  datetime ranges.
- The semantic mapper selects the axis range with the dataset's datetime
  columns, as the query object factory does.
- Time comparison queries replace or shift only the compared range and keep
  other datetime columns' ranges, as the main query applies them.

Charts with no known time column still apply the range to every
TEMPORAL_RANGE filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sadpandajoe and others added 2 commits November 28, 2026 06:46
…racking

Addresses the CodeQL py/polynomial-redos alert on _SQL_IDENTIFIER.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A time comparison chose the column to replace or shift by position: the
first TEMPORAL_RANGE filter. With another datetime range listed before the
x-axis range, a date-range comparison replaced that other range, and a
relative comparison shifted it while the x-axis stayed bounded to the main
period, so the comparison series was empty.

The comparison column is chosen as the main query chooses it: a filter on
the Time Column, the x-axis or a datetime column the x-axis reads, then the
Time Column, then the filter carrying the time range. Without a known time
column the first temporal filter is still used.

Also ignore an x_axis key in a stored query dict, which clashed with the
chart's x-axis from the form data, and test the bounded identifier regex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@aminghadersohi aminghadersohi 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.

The chart-query threads are addressed; Drill to Detail on a time cross-filter target and table time comparisons still bound a different column than the chart does.

Comment on lines +534 to +545
cross_filter_columns: set[str] = {
identifier
for filter_object in (
extra_form_data.get("filters") or []
if isinstance(extra_form_data, dict)
else []
)
if isinstance(filter_object, dict)
and filter_object.get("op") == "TEMPORAL_RANGE"
and filter_object.get("val") == query_object.time_range
for identifier in get_column_identifiers(filter_object.get("col"))
}

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.

Drill to Detail sends no extra_form_data, so on a time cross-filter target whose x-axis is created_at this set is empty: the drill rewrites created_at to the bucket and keeps the saved ds range, while the chart does the reverse, so the detail rows differ or come back empty.

Comment on lines +3880 to +3891
base_axes = get_base_axis_columns(query_object.columns)
time_columns: set[str] = {
*get_column_identifiers(query_object.granularity),
*(
identifier
for axis in base_axes[:1]
for identifier in (
*get_column_identifiers(axis),
*get_axis_temporal_columns(axis, get_temporal_column_names(self)),
)
),
}

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.

A table sends its temporal groupby as BASE_AXIS with no x-axis, so with a saved created_at range and the dashboard range on ds, a relative comparison shifts created_at and leaves ds unshifted (a date-range one drops ds), while the main query bounded ds.

Comment thread UPDATING.md
Comment on lines +144 to +145
from another datetime column. Charts with no known time column still apply a
time range to every `TEMPORAL_RANGE` filter. A Custom SQL x-axis without a

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.

Nit: Without a known time column the range lands only on the unbounded TEMPORAL_RANGE filters when one exists, so a categorical x-axis keeps a saved created_at range; every filter takes it only when none is unbounded.

Suggested change
from another datetime column. Charts with no known time column still apply a
time range to every `TEMPORAL_RANGE` filter. A Custom SQL x-axis without a
from another datetime column. Charts with no known time column apply a time
range to their unbounded `TEMPORAL_RANGE` filters, or else to every one. A
Custom SQL x-axis without a

Comment on lines +110 to +113
names: list[str] = [
next(group for group in match.groups() if group)
for match in _SQL_IDENTIFIER.finditer(expression)
]

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.

Nit: Every bare word counts, so on a dataset with a datetime column named date, cast(created_at as date) reads as both created_at and date: a saved date range is replaced by the dashboard range and no x-axis filter is added.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Temporal filters and granularity can diverge from the chart x-axis when multiple datetime columns exist

4 participants