Skip to content

fix(dataset): do not apply the dataset timezone to DATE columns - #45203

Merged
EnxDev merged 10 commits into
apache:masterfrom
sqlalchemy-cf-d1:fix/date-filter-timezone
Nov 2, 2026
Merged

EnxDev merged 10 commits into
apache:masterfrom
sqlalchemy-cf-d1:fix/date-filter-timezone

Conversation

@danielalyoshin

Copy link
Copy Markdown
Contributor

SUMMARY

A dataset timezone ({"timezone": "..."} in the dataset's extra settings, added in #37014) converts the time range bounds from that timezone to UTC in get_time_filter, and converts the returned values from UTC to that timezone in normalize_dttm_col. A DATE column 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:

  • SQLite compares the text, so west of UTC the range selects one day late.
  • PostgreSQL, like other databases whose convert_dttm writes a DATE bound as a date only, cuts each bound to its date, so east of UTC the range selects one day early.
  • Everywhere, each value comes back as midnight UTC and is shown at a time of day in the dataset timezone: 2026-09-20 is shown as 2026-09-19 20:00 in New York and 2026-09-20 09:00 in Tokyo. With a day grain the chart labels the New York days one day early.

This PR leaves DATE columns as they are, the same way #43173 made the Hours offset whole days for them:

  • get_time_filter keeps the bounds of a DATE column. The timezone still takes precedence over the Hours offset, and an unknown timezone still falls back to it.
  • normalize_df marks DATE columns with a new DateColumn.date_only flag, and normalize_dttm_col does not convert them. This covers the x-axis and the legacy __timestamp column.
  • The type check is the one get_effective_hours_offset already used, moved into is_date_column_type so 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.

DATETIME and TIMESTAMP columns are not affected. One side effect, also noted in UPDATING.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 Oracle DATE. Its filter bounds were already cut to the date by OracleEngineSpec.convert_dttm, and the Hours offset already treats it as whole days.

Follow-up to #44805, which fixed time filters on SQLite DATE columns without a dataset timezone.

Tests:

  • test_time_filter_timezone.py: filter bounds for a DATE column 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 __timestamp column, checking the rows and the shown values; a TIMESTAMP column that is still converted; _is_date_only_column for column objects and dicts.
  • test_core.py: normalize_dttm_col leaves a date_only column alone, and does not apply the offset in its place.

On master 8 of the new tests in test_time_filter_timezone.py fail. The PostgreSQL New York filter case passes on master, because TO_DATE cuts its bounds back to the selected days.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Rows a chart query returns for a DATE column holding 2026-09-19 to 2026-09-22, with a time range from 2026-09-20 to 2026-09-22, through /api/v1/chart/data on PostgreSQL 16 and SQLite. The results are the same with and without a day grain.

Database Dataset timezone Before: days selected Before: values returned After
PostgreSQL America/New_York 09-20, 09-21 09-19 20:00, 09-20 20:00 09-20, 09-21
PostgreSQL Asia/Tokyo 09-19, 09-20 09-19 09:00, 09-20 09:00 09-20, 09-21
SQLite America/New_York 09-21, 09-22 09-20 20:00, 09-21 20:00 09-20, 09-21
SQLite Asia/Tokyo 09-20, 09-21 09-20 09:00, 09-21 09:00 09-20, 09-21

Without a dataset timezone, and for TIMESTAMP columns, the results are the same before and after.

TESTING INSTRUCTIONS

Unit tests:

pytest tests/unit_tests/models/test_time_filter_timezone.py tests/unit_tests/models/test_hours_offset_bound_truncation.py tests/unit_tests/utils/test_core.py

By hand, on PostgreSQL:

  1. CREATE TABLE t (day DATE); INSERT INTO t VALUES ('2026-09-19'), ('2026-09-20'), ('2026-09-21'), ('2026-09-22');
  2. Create a dataset from t. In Edit dataset > Settings, set Extra to {"timezone": "Asia/Tokyo"}.
  3. Make a table chart with day as a dimension, time grain Day, metric COUNT(*), and a custom time range from 2026-09-20 to 2026-09-22.
  4. In the chart's results, before this PR day is 2026-09-19 09:00 and 2026-09-20 09:00. With it, 2026-09-20 and 2026-09-21.
  5. Set the timezone to America/New_York. Before this PR day is 2026-09-19 20:00 and 2026-09-20 20:00. With it, 2026-09-20 and 2026-09-21.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

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.
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 23faa66ac5a3

…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

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.76%. Comparing base (7519fa8) to head (529a3ed).

Files with missing lines Patch % Lines
superset/models/helpers.py 93.33% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
hive 34.49% <17.64%> (-0.01%) ⬇️
mysql 52.60% <29.41%> (-0.01%) ⬇️
postgres 52.61% <29.41%> (-0.01%) ⬇️
presto 36.22% <17.64%> (-0.01%) ⬇️
python 87.77% <94.11%> (+<0.01%) ⬆️
sqlite 52.37% <29.41%> (-0.01%) ⬇️
unit 82.53% <94.11%> (+<0.01%) ⬆️

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.

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

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.

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 13, 2026
@danielalyoshin

Copy link
Copy Markdown
Contributor Author

@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?

@danielalyoshin
danielalyoshin requested a review from EnxDev October 16, 2026 23:37
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 17, 2026

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

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.

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 20, 2026
@danielalyoshin

Copy link
Copy Markdown
Contributor Author

@aminghadersohi would you have time to review this one? It follows on from #44805. The dataset timezone was also moving DATE columns by a day, both in the time filter and in the values shown. EnxDev went through it twice with no changes asked. I just merged master in again, which also brings in the fix for the semantic layer test that was failing on master.

@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 20, 2026
@aminghadersohi
aminghadersohi self-requested a review October 20, 2026 16:23

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

@danielalyoshin thanks for this, I'm apporivng the PR but the CI should be green before to merge.

@netlify

netlify Bot commented Oct 31, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@danielalyoshin

Copy link
Copy Markdown
Contributor Author

@EnxDev thanks for the approval. The mypy failure came from #43870, which moved the time bounds logic into adjust_time_bounds, where the column can be None. Fixed in 529a3ed the same way the Hours offset code below it handles that. I don't have merge rights, so could you merge once CI is green?

@EnxDev
EnxDev merged commit cabd8d4 into apache:master Nov 2, 2026
74 checks passed
jprinet added a commit to jprinet/superset that referenced this pull request Nov 2, 2026
* 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
hainenber pushed a commit that referenced this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants