serecruit999 opened a new issue, #40807:
URL: https://github.com/apache/superset/issues/40807
### Bug description
In Superset 6.1, when a chart has Time Grain set (e.g. Year), the time range
filter is applied to the granulated expression instead of the raw column. This
is a regression from 6.0 where the filter was correctly applied to the raw
column.
**Steps to Reproduce**
Create a Bar Chart (ECharts) with GENERIC_CHART_AXES: True
Set X-axis to a datetime column (e.g. operation_completed_at)
Set Time Grain to Year
Set Time Range to Current month
Run the chart
**Expected Behavior (Superset 6.0)**
Filter is applied to the raw column. Data is found, then grouped by year:
`WHERE "operation_completed_at" >= '2026-06-01'`
**Actual Behavior (Superset 6.1)**
Filter is applied to the granulated expression. Returns 0 rows because
granulated year (2026-01-01) < current month (2026-06-01):
```
WHERE toDateTime(dateTrunc('year', toDateTime("operation_completed_at")))
>= '2026-06-01'
```
**Impact**
- Charts with Time Grain + Time Range that are not aligned (e.g. Year grain
with Current month range) return 0 rows;
- This breaks existing dashboards that worked correctly in 6.0;
- Performance degradation: applying the time filter to a granulated
expression (e.g. toDateTime(dateTrunc('year', ...))) instead of the raw column
prevents the database from using indexes on the datetime column.
### Screenshots/recordings
<img width="1535" height="772" alt="Image"
src="https://github.com/user-attachments/assets/103d3f99-595b-4cba-aa38-febf1bbd22de"
/>
<img width="1535" height="601" alt="Image"
src="https://github.com/user-attachments/assets/106033b2-730a-4f23-8288-c00745317775"
/>
### Superset version
master / latest-dev
### Python version
I don't know
### Node version
I don't know
### Browser
Chrome
### Additional context
**Environment**
Superset version: 6.1
Python: 3.12
**Datasource**
Database: ClickHouse
DB 1 clickhouse_version: 24.3.7.30
DB 2 clickhouse_version: 23.3.2.37
**Config change**
```yaml
fix_clickhouse_time_grains: |
from superset.db_engine_specs.clickhouse import
ClickHouseConnectEngineSpec
ClickHouseConnectEngineSpec._time_grain_expressions = {
None: "{col}",
"PT1S": "toDateTime(dateTrunc('second', toDateTime({col})))",
"PT1M": "toDateTime(dateTrunc('minute', toDateTime({col})))",
"PT5M": "toDateTime(toStartOfFiveMinutes(toDateTime({col})))",
"PT10M": "toDateTime(toStartOfTenMinutes(toDateTime({col})))",
"PT15M":
"toDateTime(toStartOfFifteenMinutes(toDateTime({col})))",
"PT30M": "toStartOfInterval(toDateTime({col}), INTERVAL 30
minute)",
"PT1H": "toDateTime(dateTrunc('hour', toDateTime({col})))",
"P1D": "toDateTime(dateTrunc('day', toDateTime({col})))",
"P1W": "toDateTime(dateTrunc('week', toDateTime({col})))",
"P1M": "toDateTime(dateTrunc('month', toDateTime({col})))",
"P3M": "toDateTime(dateTrunc('quarter', toDateTime({col})))",
"P1Y": "toDateTime(dateTrunc('year', toDateTime({col})))",
}
```
### 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]