Repository navigation
fix(models): make naive datetime object timezone-aware before converting to unix timestamp - #39782
Conversation
Code Review Agent Run #0014a6Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
c097733 to
6e2720b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39782 +/- ##
==========================================
- Coverage 64.36% 64.36% -0.01%
==========================================
Files 2653 2653
Lines 145118 145121 +3
Branches 33473 33474 +1
==========================================
- Hits 93411 93406 -5
- Misses 50016 50022 +6
- Partials 1691 1693 +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:
|
801d31c to
992e9b0
Compare
992e9b0 to
ec790df
Compare
Code Review Agent Run #8e8ef1Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
@Mayankaggarwal8055 Thanks for the feedback, and sorry for the late reply!
Good point.
It relies on how Python implicitly handles timezone-naive timestamps. |
Code Review Agent Run #24174Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
Running CI 🤞 Noting that #40034 tackles this implementation as well... taking a look at that too. |
|
This fix makes the test environment-independent, but it does so by changing the nature of the test input — the datetimes are no longer naive. The production code path being tested (dttm.timestamp() on a naive datetime) is what actually runs in the real application, because the callers throughout the Superset codebase pass naive datetimes. So the test is now no longer testing the real code path — it's testing a scenario that doesn't happen in practice (a timezone-aware input), and the underlying bug in the implementation (where a naive datetime produces a timezone-dependent epoch) remains live and unfixed. The best aproach would be to combine elements of both...
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes flaky unit tests that depended on the host environment’s local timezone by making the test datetimes explicitly timezone-aware (UTC) so they compare correctly against epoch-based expected values.
Changes:
- Import
timezoneand usetimezone.utcon test datetimes used for epoch formatting assertions - Add clarifying comments explaining timezone-naive vs timezone-aware expectations in the parametrized test data
a56bf63 to
14ea0eb
Compare
@rusackas Thank you for the clarification. As suggested, I have reverted my own changes to the unit test, and applied @charliesheh 's ideas from #40034 . |
bac86f2 to
9dcf023
Compare
|
/review |
9dcf023 to
9eb7e03
Compare
There was a problem hiding this comment.
Code Review Agent Run #354d9b
Actionable Suggestions - 1
-
superset/models/helpers.py - 1
- Assert statement used in production code · Line 2401-2401
Review Details
-
Files reviewed - 1 · Commit Range:
52fa7f3..9dcf023- superset/models/helpers.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 [email protected].
Documentation & Help
|
/review |
Code Review Agent Run #ad8868Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #319287Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
There was a problem hiding this comment.
Thanks for circling back on this, and for your patience. The if tzinfo is None guard with timezone.utc LGTM, and avoids the clobbering-aware-datetimes issue that the unconditional replace() in #40034 would hit. I'm good with this approach. I'm considering closing #40034 in favor of this one so we're not landing the same fix twice — feel free to rebase when possible (there's currently a conflict), and we can take that route. 🤞
9eb7e03 to
8cd54d9
Compare
@rusackas As suggested, I rebased in order to resolve the merge conflicts. env TZ='US/Eastern' python3 -m pytest tests/unit_tests/models/core_test.py -k test_dttm_sql_literalReady whenever you are! :-) |
Code Review Agent Run #90dae2Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
Approving CI, for starters.
This seems to be landing the right fix: dttm.timestamp() interprets naive datetimes as local time, so epoch_s/epoch_ms output drifted with the server's TZ. Forcing UTC before timestamp() in dttm_sql_literal makes it deterministic, and replace() keeps it non-mutating.
Approving, but the only nit is the title still says test: when this is really a fix(models): change. Happy to change the title if you'd like me to.
|
| Language | Fuzzy before | Fuzzy after | New |
|---|---|---|---|
de |
0 | 997 | +997 |
fi |
4815 | 4823 | +8 |
it |
1665 | 1667 | +2 |
ko |
1519 | 1521 | +2 |
th |
4815 | 4823 | +8 |
How to fix
1. Install dependencies (if not already set up):
pip install -r superset/translations/requirements.txt
sudo apt-get install gettext # or: brew install gettext2. Re-extract strings and sync .po files:
./scripts/translations/babel_update.shThis rewrites superset/translations/messages.pot from the current source files and merges the changes into every .po file. Strings whose msgid changed will be marked #, fuzzy.
3. Resolve the fuzzy entries in the affected language files (de, fi, it, ko, th):
grep -n '#, fuzzy' superset/translations/<lang>/LC_MESSAGES/messages.poFor each fuzzy entry, either rewrite the msgstr to match the new string and remove the #, fuzzy line, or clear the msgstr to "" if you cannot provide a translation.
4. Commit your changes to the .po files.
…one-specific timestamp.
8cd54d9 to
9093f93
Compare
@rusackas Thanks, I updated the title! By the way, GitHub Actions sent a message regarding translations. #39782 (comment) |
|
Thanks again! |
|
Bito Automatic Review Skipped – PR Already Merged |
…ing to unix timestamp (apache#39782) Co-authored-by: Hans Yu <[email protected]>
…xtra values Rebases the DST-aware timezone conversion onto master, which since merged apache#41391's fixed Hour Offset shift for the same get_time_filter method. The two mechanisms now layer instead of conflict: a configured extra.timezone takes precedence (it is strictly more correct, since it handles DST), and the legacy Hour Offset still applies exactly as before when no timezone is configured. Also addresses two outstanding review threads on get_time_filter: - get_dataset_timezone now validates that extra["timezone"] is a string before returning it, since extra is arbitrary user-supplied JSON and a non-string value would otherwise reach ZoneInfo() and raise TypeError. get_time_filter also catches TypeError alongside ZoneInfoNotFoundError as defense in depth. - Confirmed the epoch-rendering concern (naive datetime .timestamp() being interpreted in the server's local timezone) is already fixed on master via apache#39782's UTC-anchoring in dttm_sql_literal; added a regression test tying it to the dataset-timezone path specifically. Adds test coverage for the reconciliation (offset-only fallback, timezone taking precedence over a configured offset) and the non-string timezone guard. Co-Authored-By: Claude <[email protected]>
Fixes #39781 .
SUMMARY
Currently, two testcases rely on the environment to have UTC timezone in order to pass.
The problem is that given timestamp is timezone-native, and that the solution timestamp is a UNIX timestamp, and thus timezone-aware.
Fix the timezone for those timestamps.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
This test passes here but not on the main branch:
ADDITIONAL INFORMATION