Skip to content

fix(utils): datetime_to_epoch function is fixed to timezone aware epoch#37979

Merged
hainenber merged 2 commits intoapache:masterfrom
tzercin:fix/37947-timezone-aware-epoch
Feb 15, 2026
Merged

fix(utils): datetime_to_epoch function is fixed to timezone aware epoch#37979
hainenber merged 2 commits intoapache:masterfrom
tzercin:fix/37947-timezone-aware-epoch

Conversation

@tzercin
Copy link
Contributor

@tzercin tzercin commented Feb 14, 2026

SUMMARY

Fixes an epoch-shift bug in Explore Results when switching “Formatted date” ↔ “Original value” by correcting timezone-aware datetime → epoch conversion to preserve the absolute instant.

Convert tz-aware datetimes to UTC using astimezone(pytz.utc) instead of re-labeling tzinfo with replace(tzinfo=UTC).
Add a regression unit test covering tz-aware datetime serialization to epoch.

replace(tzinfo=UTC) changes the represented instant for tz-aware datetimes, causing offsets like +8 hours in the serialized epoch; astimezone(UTC) performs a true conversion and keeps the instant consistent.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
Screenshot 2026-02-15 at 00 21 58
Screenshot 2026-02-15 at 00 22 06

After:
Screenshot 2026-02-15 at 00 21 09

Screenshot 2026-02-15 at 00 21 31

TESTING INSTRUCTIONS

  • Create a local postgres db instance on docker with a certain timezone other than UTC.
    docker run -d --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e TZ=Asia/Shanghai -p 5432:5432 postgres:latest
  • Create an example dataset on this DB which looks like this:
Screenshot 2026-02-15 at 00 26 58 - Explore the dataset as explained in the issue. - Also you can run this test: `python -m pytest tests/unit_tests/utils/json_tests.py::test_json_int_dttm_ser`

ADDITIONAL INFORMATION

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 14, 2026

Code Review Agent Run #05de82

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: a202345..a202345
    • superset/utils/dates.py
    • tests/unit_tests/utils/json_tests.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot bot added the change:backend Requires changing the backend label Feb 14, 2026
@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.43%. Comparing base (76d897e) to head (3a7ea4e).
⚠️ Report is 3751 commits behind head on master.

Files with missing lines Patch % Lines
superset/utils/dates.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #37979      +/-   ##
==========================================
+ Coverage   60.48%   66.43%   +5.94%     
==========================================
  Files        1931      668    -1263     
  Lines       76236    51322   -24914     
  Branches     8568     5776    -2792     
==========================================
- Hits        46114    34096   -12018     
+ Misses      28017    15840   -12177     
+ Partials     2105     1386     -719     
Flag Coverage Δ
hive 41.47% <0.00%> (-7.68%) ⬇️
javascript ?
mysql 64.53% <0.00%> (?)
postgres 64.61% <0.00%> (?)
presto 41.49% <0.00%> (-12.32%) ⬇️
python 66.40% <0.00%> (+2.90%) ⬆️
sqlite 64.20% <0.00%> (?)
unit 100.00% <ø> (+42.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@hainenber
Copy link
Contributor

@tzercin thanks for opening out a PR! That said, can you fix the lint issue reported by Ruff, i.e. the un-sorted import?

@tzercin
Copy link
Contributor Author

tzercin commented Feb 15, 2026

Oh sorry, I fixed it now!

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 15, 2026

Code Review Agent Run #a3a383

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: a202345..3a7ea4e
    • superset/utils/dates.py
    • tests/unit_tests/utils/json_tests.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@hainenber hainenber merged commit 440602e into apache:master Feb 15, 2026
66 of 67 checks passed
@hainenber
Copy link
Contributor

Thanks @tzercin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] : Incorrect Datetime Conversion When Switching Display Formats in Bar Chart (Latest Master Branch)

2 participants