Mark-Onopchenko opened a new issue, #45796:
URL: https://github.com/apache/superset/issues/45796
### Bug description
On a Timeseries chart, an **Event**, **Interval** or **Time Series**
annotation layer can be sourced from another saved chart (a Table or Line
chart). The layer popover (Explore > Data > Annotations and Layers > layer >
Annotation Slice Configuration) offers **Override time range** and **Override
time grain**, described as controlling whether the host chart's time range /
time grain "should be passed down to the chart containing the annotation data".
Neither checkbox has any effect on charts with a generic x-axis (every
modern chart type). The source chart always runs with its own saved time range
and time grain. Explicit values sent through the API, e.g. `"overrides":
{"time_range": "2005-01-01 : 2006-01-01"}`, are ignored as well.
**Override time range is checked by default** whenever a source chart is
picked, so almost every chart-sourced layer in the wild has `{"time_range":
null}` stored and silently gets the source chart's full range.
#### Steps to reproduce (example data, `cleaned_sales_data`)
1. Source chart "Problem orders": Table chart, query mode Aggregate,
dimensions `order_date` (Time grain Day), `country`, `order_number`, `status`;
filter `status IN (Cancelled, Disputed)`; time filter **No filter**. It lists 7
orders spanning 2003-10-23 to 2005-05-13.
2. Host chart "Sales Linear": Line chart, x-axis `order_date`, Time grain
Month, metric `SUM(sales)`, time range `2004-01-01 <= col < 2005-01-01`.
3. On the host add an annotation layer: type Event, source Table, chart
"Problem orders", event time column `order_date`, title column `status`. Leave
**Override time range** checked. Save.
4. Call `POST /api/v1/chart/data` with the host's query context, `"force":
true`, and count `result[0].annotation_data["Problem orders"].records` while
editing `queries[0].annotation_layers[0].overrides`:
| Case | `overrides` on the layer | Actual | Expected |
|---|---|---|---|
| A | `{"time_range": null}` (checkbox on) | 7 | 3 (the 2004 orders) |
| B | `{"time_range": "2005-01-01 : 2006-01-01"}` (edited payload) | 7 | 3
(the 2005 orders) |
| C | `{}` (checkbox off) | 7 | 7 (source's own range) |
The same happens for the time grain. With a second source (Line chart on
`cleaned_sales_data` at Time grain Day) added as a Time Series layer with
**Override time grain** checked on the Month-grain host:
| Case | `overrides` on the layer | Actual | Expected |
|---|---|---|---|
| G1 | `{"time_grain_sqla": null, "granularity": null}` (checkbox on) | 117
daily records | 12 monthly records |
| G2 | `{"time_grain_sqla": "P1M"}` (edited payload) | 117 daily records |
12 monthly records |
| G3 | `{}` (checkbox off) | 117 daily records | 117 daily records |
Verified on current `master` (f1d19c72aa).
#### Root cause
All in `QueryContextProcessor.get_viz_annotation_data`
(`superset/common/query_context_processor.py`):
1. **`null` cannot inherit.** The checkboxes store the key with a `null`
value, meaning "use the host's value", but the function only receives the layer
and `force`; the host `QueryObject` is never passed in, so
`overrides.get("time_range")` is falsy and the branch is skipped. (The legacy
frontend path `runAnnotationQuery` used to fill the nulls client-side; the
chart-data path sends them through untouched.)
2. **Explicit time ranges go to the wrong fields.** The value is written to
`from_dttm` / `to_dttm`, which only reach SQL on the legacy `granularity` path.
Generic x-axis charts carry their window in a `TEMPORAL_RANGE` filter clause,
which is what `QueryContextFactory._apply_filters` rewrites for dashboard time
filters.
3. **Explicit time grains go to the wrong field.** The value is written to
`extras["time_grain_sqla"]`, also legacy-only. Generic x-axis charts carry the
grain as `timeGrain` on their `BASE_AXIS` column.
#### Related
- #36966 reported the same symptoms (closed by #38126, which only fixed time
shift rendering in the ECharts plugin; the range and grain overrides were left
as-is).
- #25300 reported it for Line Chart [Legacy] sources and was closed as stale.
### Screenshots/recordings
_Before: host restricted to 2004, Daily sales layer with Override time grain
checked still drawn at Day grain._
(screenshot: before-grain-layer.png)
### Superset version
master / latest-dev
### Python version
3.11
### Node version
18 or greater
### Browser
Chrome
### Additional context
Docker Compose dev environment with example data loaded; no feature flags
beyond the defaults. A fix is in the linked PR.
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to
my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug
report.
- [x] I have checked Superset's logs for errors and if I found a relevant
Python stacktrace, I included it here as text in the "additional context"
section.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]