Repository navigation
fix(query): take chart time bounds from the temporal x-axis only - #46345
sadpandajoe wants to merge 5 commits into
Conversation
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>
| if not base_axes or ( | ||
| temporal_columns is not None | ||
| and cast(Mapping[str, object], base_axes[0]).get("sqlExpression") | ||
| not in temporal_columns | ||
| ): | ||
| return cast(str, temporal_filters[0].get("val")) |
There was a problem hiding this comment.
Suggestion: For an axis like DATE(ds), this returns the first unrelated temporal filter before checking for an axis match, so the query gets bounds from the wrong column.
Assessment: 🟠 Major · 🔁 Occurrence: Sometimes · 🏷️ Incorrect condition logic
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/common/utils/time_range_utils.py
**Line:** 58:63
**Comment:**
*Incorrect Condition Logic: For an axis like `DATE(ds)`, this returns the first unrelated temporal filter before checking for an axis match, so the query gets bounds from the wrong column.
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #46345 +/- ##
==========================================
+ Coverage 85.66% 85.68% +0.01%
==========================================
Files 3111 3110 -1
Lines 214938 215616 +678
Branches 50908 50817 -91
==========================================
+ Hits 184136 184751 +615
- Misses 27381 27446 +65
+ Partials 3421 3419 -2
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:
|
# Conflicts: # tests/unit_tests/common/test_time_range_utils.py
aminghadersohi
left a comment
There was a problem hiding this comment.
Time comparison on a temporal x-axis returns an empty series when the chart also filters another datetime column.
| else: | ||
| targets = temporal_filters |
There was a problem hiding this comment.
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.
| return cast(str, selected.get("val")) | ||
| base_axes: list[Column] = get_base_axis_columns(columns) | ||
| if not base_axes or ( | ||
| temporal_columns is not None |
There was a problem hiding this comment.
Nit: _get_adhoc_filters in semantic_layers/mapper.py still calls this without temporal_columns, so for a categorical x-axis it now selects No filter while the factory used the first range, and that range filter is no longer dropped in favour of the factory bounds.
…ts it Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
aminghadersohi
left a comment
There was a problem hiding this comment.
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.
| base_axes: list[Column] = get_base_axis_columns( | ||
| getattr(query_object, "columns", None) | ||
| ) |
There was a problem hiding this comment.
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.
| for filter_object in temporal_filters | ||
| if time_columns.intersection(get_column_identifiers(filter_object["col"])) | ||
| ] | ||
| if not targets and not isinstance(granularity, str): |
There was a problem hiding this comment.
With a Custom SQL x-axis such as DATE(created_at), _apply_granularity sets the main datetime column as granularity, so nothing matches and this branch is skipped: the dashboard range bounds only ds, and created_at days outside it show on the axis (base bounded both).
| targets: list[QueryObjectFilterClause] = [ | ||
| filter_object | ||
| for filter_object in temporal_filters | ||
| if time_columns.intersection(get_column_identifiers(filter_object["col"])) | ||
| ] |
There was a problem hiding this comment.
Time x-axis cross-filters send the clicked bucket as time_range and rely on every TEMPORAL_RANGE being rewritten (see EchartsTimeseries.tsx); a target on another datetime x-axis now has that axis bounded to the bucket and keeps its saved range, so a disjoint saved range empties it.
| # Time comparison shifts only the first temporal range, so the | ||
| # x-axis range goes first. | ||
| query_object.filter.insert(0, axis_filter) |
There was a problem hiding this comment.
With DATE_RANGE_TIMESHIFTS_ENABLED, a date-range offset drops every TEMPORAL_RANGE and re-adds only the x-axis one, so the comparison series ignores the created_at range this change now keeps on the main series.
SUMMARY
Supersedes #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:
get_time_range_from_filters(called byQueryObjectFactoryto computefrom_dttm/to_dttm) compared eachTEMPORAL_RANGEfilter'scolonly with the x-axis label and otherwise fell back to the firstTEMPORAL_RANGEfilter (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 whosecolis an adhoc column, never matched.QueryContextFactory._apply_filterswrotetime_rangeinto everyTEMPORAL_RANGEfilter (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:
TEMPORAL_RANGEfilters by label and then by expression, accepting plain strings and adhoc column dicts.TEMPORAL_RANGEfilters 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, everyTEMPORAL_RANGEfilter takes the range as before._apply_granularityunchanged, so the dashboard Time Column override and the x-axis label it preserves keep working.TESTING INSTRUCTIONS
order_dateandship_date.order_date, a time filterorder_date= No filter, and a second adhoc filtership_datewith a range that excludes some rows. Save it to a dashboard with a Time Range native filter and pick a range.order_dateby the dashboard range and still applies the chart's ownship_daterange. Before this change both columns were bounded by the dashboard range.order_datetime filter from the chart: the query still boundsorder_dateby the dashboard range and keepsship_date's own range. Before this changeorder_datewas unbounded andship_datetook the dashboard range.ship_dateon a dataset whose main datetime column isorder_date, with aship_datetime filter: bothorder_dateandship_dateare bounded by the dashboard range.status) with only a time filter onorder_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 noTEMPORAL_RANGEon 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 intest_query_context_factory.pyand the expected bar counts of five setups intest_drill_by_time_column.py(the February order shipped in July now stays outside the chart's ownship_daterange). The drill-by contract, that drill rows equal the clicked bar, still holds.Notes:
_apply_granularityis left untouched.TEMPORAL_RANGEfilter (_get_temporal_column_for_filter); this PR does not change that path.🤖 Generated with Claude Code