Skip to content

fix(explore): apply the dataset timezone to grained temporal filter values - #46175

Merged
aminghadersohi merged 3 commits into
masterfrom
fix-grained-filter-dataset-timezone
Nov 22, 2026
Merged

aminghadersohi merged 3 commits into
masterfrom
fix-grained-filter-dataset-timezone

Conversation

@aminghadersohi

Copy link
Copy Markdown
Contributor

SUMMARY

On a dataset with a valid non-UTC extra.timezone, temporal buckets are grouped on the stored UTC value and then moved into the dataset timezone for display (normalize_dttm_col). Grained comparisons (==, !=, IN, NOT IN, <, >, <=, >= with a grain, as sent by cross-filters and Drill to detail) sent that displayed local label back unchanged. It was compared against the UTC bucket, so a one-row bucket matched 0 rows for ==/IN, and NOT IN kept rows it should have excluded. This happens whatever the engine's SQL-shift capability, because a configured timezone disables the SQL shift.

filter_values_handler already inverted the Hours offset for these values; it now takes a temporal_timezone and converts the label from the dataset timezone back to UTC the same way, for every value shape it accepts (epoch milliseconds, numeric strings, datetimes, ISO strings). Aware values are left alone, as they already name an instant.

Unchanged: UTC datasets and datasets with no timezone, invalid timezones (still fall back to the Hours offset), DATE columns (a date has no time of day for the zone to move), ungrained filters and TEMPORAL_RANGE (already converted in adjust_time_bounds).

Known limitation: a label that falls in a DST fold hour maps back to its first occurrence.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A, backend only.

TESTING INSTRUCTIONS

pytest tests/unit_tests/models/test_hours_offset_bound_truncation.py

The new tests (test_grained_drill_with_valid_dataset_timezone_matches_displayed_bucket, test_display_only_bucket_timezone_value_formats, test_grained_drill_value_conversion_skips_date_columns) fail on master: grained ==/IN/NOT IN, two zones, Hours offsets 0/1/-1, both SQL-shift capability modes.

Manual: set a dataset's extra to {"timezone": "America/Los_Angeles"}, chart a grained temporal dimension (for example a Sunburst or Table with Drill to detail), and drill into a day bucket; the rows match the bucket's count.

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

…alues

A dataset with a valid non-UTC timezone groups temporal buckets on the stored
UTC value, then pandas moves each bucket label into that timezone for display.
Grained ==, !=, IN, NOT IN and range comparisons (cross-filters, Drill to
detail) sent that local label back unchanged, so they compared a local wall
time against a UTC bucket and selected the wrong rows.

Convert the label back to UTC before comparing, for every value shape the
filter accepts (epoch milliseconds, numeric strings, datetimes, ISO strings).
DATE columns, UTC datasets, datasets without a timezone and invalid timezones
keep their existing behavior.
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.28%. Comparing base (e46b5e5) to head (9d6fc8d).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
superset/models/helpers.py 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46175      +/-   ##
==========================================
- Coverage   85.37%   85.28%   -0.09%     
==========================================
  Files        3098     3090       -8     
  Lines      213116   212454     -662     
  Branches    50276    49968     -308     
==========================================
- Hits       181938   181186     -752     
- Misses      27744    27840      +96     
+ Partials     3434     3428       -6     
Flag Coverage Δ
hive 34.02% <4.16%> (-0.01%) ⬇️
mysql 51.68% <12.50%> (-0.01%) ⬇️
postgres 51.72% <12.50%> (?)
presto 35.67% <12.50%> (-0.01%) ⬇️
python 88.17% <91.66%> (+<0.01%) ⬆️
sqlite 51.39% <12.50%> (-0.01%) ⬇️
unit 83.35% <91.66%> (+<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.

@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Product acceptance at 068d155: ship.

I ran the PR head in-process against a real PostgreSQL 17 database (2,000 rows, TIMESTAMP, TIMESTAMPTZ and DATE columns) through the real /api/v1/chart/data and /datasource/samples routes. Each bucket label the grouped query returned was sent back as a grained filter.

America/Los_Angeles, day grain, 52 buckets:

check merge base head expected
Drill to detail ==, buckets with the wrong count 52 of 52 (a 39-row bucket gave 0) 0 0
IN on 3 buckets 0 116 116
NOT IN on the same 3 2000 1884 1884
  • These numbers are the same for TIMESTAMPTZ and for a dataset that also has an Hours offset of 1. Asia/Kolkata >= went from 1187 to 1226 (expected 1226).
  • Other grains, buckets with the wrong count, base → head: P1M 3/3 → 0, P1W 9/9 → 0, PT1H Kolkata 1240/1240 → 0, PT1H LA with ISO-string or string-epoch values 711/1240 → 0.
  • Unchanged, identical counts on base and head: UTC, no timezone, Hours offset only, invalid timezone (still uses the offset), DATE columns, TEMPORAL_RANGE, and ungrained comparisons.
  • A Gamma user with access to one dataset got the same results and still gets 403 on the other datasets.
  • tests/unit_tests/models/test_hours_offset_bound_truncation.py: with only superset/models/helpers.py reverted to the merge base, 46 tests fail; at head, all 554 pass.

One LOW note, already listed as a known limitation in the description. On the fall-back DST day, hour grain shows two buckets labelled 01:00. Both map back to the first one (2026-11-01T01:00:00 becomes 08:00 UTC), so drilling the second bucket returns the first bucket's rows. The label alone cannot tell them apart, so I don't think this PR needs a change for it.

@aminghadersohi
aminghadersohi marked this pull request as ready for review November 13, 2026 21:27
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; the tests cover all grained comparison operators and verify that offset-aware values are preserved.

Assessed commit: 9d6fc8d43062

@netlify

netlify Bot commented Nov 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aminghadersohi, nice to see the timezone case handled the same way as the Hours offset, and the real-Postgres check against every bucket is reassuring. LGTM!

@aminghadersohi

Copy link
Copy Markdown
Contributor Author

Thanks @rusackas for the review.

@aminghadersohi
aminghadersohi merged commit 611b2a5 into master Nov 22, 2026
77 checks passed
@aminghadersohi
aminghadersohi deleted the fix-grained-filter-dataset-timezone branch November 22, 2026 00:56
jprinet added a commit to jprinet/superset that referenced this pull request Nov 23, 2026
* origin/master: (393 commits)
  fix(a11y): name the semantic view description input (apache#46458)
  docs(semantic): explain datasource list modification eligibility (apache#46462)
  docs(semantic-layer): document NULL-preserving exclusion filters (apache#46447)
  fix(uploads): skip folder and system entries in columnar ZIP uploads (apache#45617)
  fix(i18n-es): promote 47 of the zero-context backfill entries (apache#45847)
  fix(mcp): return structured ChartError on SQLAlchemyError in get_chart_sql (apache#44351)
  fix(datasets): follow semantic view modification permissions (apache#46448)
  fix(docker): account for container memory limits in frontend-mem-nag.sh (apache#46373)
  fix(reports): carry the report's native filters in the email and Slack link (apache#46062)
  fix(explore): apply the dataset timezone to grained temporal filter values (apache#46175)
  fix(i18n): enforce the do-not-translate registry across the catalogs (apache#45974)
  chore(logging): log unparseable virtual dataset SQL at debug in the RLS lookup (apache#46139)
  fix(i18n): split parameter-suggestion plural into two messages (apache#46049)
  test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration (apache#46319)
  perf(dashboard): look up the dashboard once per filter_state read (apache#46314)
  fix(i18n): load the dayjs locale for every language with a catalog (apache#45982)
  test(semantic-layer): make date export parametrization deterministic (apache#46449)
  fix(oauth2): idempotent OAuth2 completion and resilient listener (apache#40292)
  fix(explore): prevent full table scan when SQL expression is used as x-axis (apache#41339)
  feat(mcp): radar chart type plugin (apache#43571)
  ...

# Conflicts:
#	.github/workflows/docker.yml
#	.github/workflows/superset-frontend.yml
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.

3 participants