Repository navigation
fix(dataset): do not apply the dataset timezone to DATE columns - #45203
Conversation
A dataset timezone converted time filter bounds to UTC and returned values from UTC. A DATE column has no time of day, so both conversions moved it by part of a day: on SQLite a range west of UTC selected one day late, on PostgreSQL a range east of UTC selected one day early, and every value was shown at a time of day, often on the day before. get_time_filter keeps the bounds of a DATE column, and normalize_dttm_col leaves its values alone through a new DateColumn.date_only flag. The timezone still takes precedence over the Hours offset. The DATE check is the one get_effective_hours_offset already used, now shared as is_date_column_type.
…back The DATE check ran inside the try that catches TypeError for an invalid timezone, so an error while reading the column type would have been logged as an invalid timezone and dropped a valid one. It now runs before the try. Tests: docstrings and type hints for the new helpers, and the in-memory SQLite connection is closed and the engine disposed after each test.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45203 +/- ##
=======================================
Coverage 84.76% 84.76%
=======================================
Files 3072 3072
Lines 206119 206129 +10
Branches 48539 48541 +2
=======================================
+ Hits 174718 174731 +13
+ Misses 28101 28100 -1
+ Partials 3300 3298 -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:
|
EnxDev
left a comment
There was a problem hiding this comment.
Went through both halves, the filter bounds in get_time_filter and the display conversion in normalize_dttm_col, and they line up. The type check is the same one the Hours offset already uses, an unknown timezone still falls back to the offset, and TIMESTAMP columns are untouched. The SQLite end-to-end tests make the before and after easy to trust.
No inline notes. The Oracle DATE trade-off is called out in UPDATING.md, which is the right place for it.
|
@EnxDev thanks for the review. I merged master in, only UPDATING.md conflicted. Would you be able to approve if it looks good to you? |
EnxDev
left a comment
There was a problem hiding this comment.
Still looks good after the master merge. The only change to this PR's own files is the UPDATING.md conflict, and the entry still sits under Next.
The red unit-tests check is test_unsupported_operator_fails_loudly in the semantic layer stub tests, which fails on master too, so it isn't coming from this change. No inline notes.
|
@aminghadersohi would you have time to review this one? It follows on from #44805. The dataset timezone was also moving |
EnxDev
left a comment
There was a problem hiding this comment.
@danielalyoshin thanks for this, I'm apporivng the PR but the CI should be green before to merge.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
* origin/master: (303 commits) fix(dashboard): don't hang forever when saved native filter state request stalls (apache#45928) chore(deps): bump actions/setup-python from 7.0.0 to 7.1.0 in the gh-actions group (apache#45941) chore(deps): bump Kesin11/actions-timeline from 3.2.0 to 3.2.1 (apache#45942) chore(deps-dev): bump the babel group across 2 directories with 2 updates (apache#45943) chore(deps-dev): bump webpack in /docs (apache#45944) chore(deps): bump unist-util-visit from 5.1.0 to 5.2.0 in /docs (apache#45945) chore(deps): bump antd from 6.6.7 to 6.6.8 in /docs (apache#45946) chore(deps): bump antd from 6.6.7 to 6.6.8 in /superset-frontend (apache#45948) fix(dataset): do not apply the dataset timezone to DATE columns (apache#45203) chore(deps-dev): update pyathena requirement from <5,>=4.1.0 to >=4.2.1,<5 (apache#45915) chore(deps): bump flask-appbuilder from 5.2.3 to 5.3.0 (apache#45922) perf(explore): use useDeferredValue for TextControl inputs (apache#44878) chore(deps-dev): bump pandas-gbq from 0.35.2 to 0.35.3 (apache#45917) chore(deps-dev): bump pymssql from 2.4.4 to 2.4.5 (apache#45919) chore(deps): bump wtforms from 3.2.2 to 3.3.0 (apache#45920) chore(deps-dev): bump grpcio from 1.84.0 to 1.84.1 (apache#45918) chore(deps-dev): bump fonttools from 4.62.0 to 4.67.0 (apache#45921) chore(deps): bump the security group across 2 directories with 2 updates (apache#45924) fix(echarts): draw the series line style and symbol in the Plain Top/Bottom legend (apache#45648) fix(ci): grant contents: read to Python jobs that declare id-token permissions (apache#45899) ... # Conflicts: # .github/workflows/chromatic.yml # .github/workflows/superset-e2e.yml # .github/workflows/superset-frontend.yml # superset-frontend/package.json
Co-authored-by: Enzo Martellucci <[email protected]>
SUMMARY
A dataset timezone (
{"timezone": "..."}in the dataset's extra settings, added in #37014) converts the time range bounds from that timezone to UTC inget_time_filter, and converts the returned values from UTC to that timezone innormalize_dttm_col. ADATEcolumn holds calendar days with no time of day, so both conversions move it by part of a day, and what goes wrong depends on the database:convert_dttmwrites aDATEbound as a date only, cuts each bound to its date, so east of UTC the range selects one day early.This PR leaves
DATEcolumns as they are, the same way #43173 made the Hours offset whole days for them:get_time_filterkeeps the bounds of aDATEcolumn. The timezone still takes precedence over the Hours offset, and an unknown timezone still falls back to it.normalize_dfmarksDATEcolumns with a newDateColumn.date_onlyflag, andnormalize_dttm_coldoes not convert them. This covers the x-axis and the legacy__timestampcolumn.get_effective_hours_offsetalready used, moved intois_date_column_typeso both use it.Both parts are needed. With only the filter fixed, PostgreSQL in New York selects the right days but still labels them one day early.
DATETIMEandTIMESTAMPcolumns are not affected. One side effect, also noted inUPDATING.md: a column that Superset reads as a date type is left alone even if the database stores a time of day in it, such as OracleDATE. Its filter bounds were already cut to the date byOracleEngineSpec.convert_dttm, and the Hours offset already treats it as whole days.Follow-up to #44805, which fixed time filters on SQLite
DATEcolumns without a dataset timezone.Tests:
test_time_filter_timezone.py: filter bounds for aDATEcolumn on SQLite and PostgreSQL in New York and Tokyo; the timezone still taking precedence over a whole-day Hours offset; an unknown timezone falling back to it; chart queries on an in-memory SQLite with and without a day grain and through the legacy__timestampcolumn, checking the rows and the shown values; aTIMESTAMPcolumn that is still converted;_is_date_only_columnfor column objects and dicts.test_core.py:normalize_dttm_colleaves adate_onlycolumn alone, and does not apply the offset in its place.On master 8 of the new tests in
test_time_filter_timezone.pyfail. The PostgreSQL New York filter case passes on master, becauseTO_DATEcuts its bounds back to the selected days.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Rows a chart query returns for a
DATEcolumn holding 2026-09-19 to 2026-09-22, with a time range from 2026-09-20 to 2026-09-22, through/api/v1/chart/dataon PostgreSQL 16 and SQLite. The results are the same with and without a day grain.Without a dataset timezone, and for
TIMESTAMPcolumns, the results are the same before and after.TESTING INSTRUCTIONS
Unit tests:
By hand, on PostgreSQL:
CREATE TABLE t (day DATE); INSERT INTO t VALUES ('2026-09-19'), ('2026-09-20'), ('2026-09-21'), ('2026-09-22');t. In Edit dataset > Settings, set Extra to{"timezone": "Asia/Tokyo"}.dayas a dimension, time grain Day, metricCOUNT(*), and a custom time range from 2026-09-20 to 2026-09-22.dayis 2026-09-19 09:00 and 2026-09-20 09:00. With it, 2026-09-20 and 2026-09-21.America/New_York. Before this PRdayis 2026-09-19 20:00 and 2026-09-20 20:00. With it, 2026-09-20 and 2026-09-21.ADDITIONAL INFORMATION