Repository navigation
fix(tz): default to UTC when /etc/localtime is a bare zoneinfo copy - #1079
Open
faresrafat3 wants to merge 1 commit into
Open
faresrafat3 wants to merge 1 commit into
faresrafat3 wants to merge 1 commit into
Conversation
_get_unix_timezone returned a Timezone with key=None when /etc/localtime was a regular file (Slurm/minimal containers). pendulum.now() then crashed in the Rust precise_diff helper, which casts the key to str. Fall through to the existing UTC default when from_file yields a keyless Timezone. Pass the file path as the key in _tz_from_env so that path never produces a keyless Timezone. Closes python-pendulum#989.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pendulum.now()crashed withTypeError: 'None' is not an instance of 'str'when
/etc/localtimeis a bare copy of a zoneinfo file (minimal containers,Slurm jobs).
_get_unix_timezonereturned aTimezonewhosekeyisNone,and the Rust
precise_diffhelper assumed the key is astr.Root cause:
_get_unix_timezonefalls through toTimezone.from_file(f)whenno named configuration is found. A zoneinfo file without an IANA key yields a
Timezonewithkey is None.precise_diffthen callsget_tz_name, whichcasts that
NonetoPyStringand raises.Verification
Fix
When the bare-file fallback yields a keyless
Timezone, fall through to theexisting UTC default (with the existing warning) instead of returning it.
Timezone.from_fileitself still allows a keyless result for pickling andutcoffsetuse, sotest_from_file_without_a_key_can_be_pickledstillpasses.
_tz_from_envnow passes the file path as the key so that path neverproduces a keyless
Timezone.New test
test_unix_localtime_regular_file_defaults_to_utcbuilds a root with/etc/localtimeas a regular file and asserts the resolver returns a named(
UTC) timezone. Against the unfixed code this test fails (resolver returnsthe keyless
Timezone).What I did not verify
Timezone.from_file(f)called directly with no key still produces akeyless
Timezone;precise_diffagainst it still crashes in the Rustextension. A one-line guard in
rust/src/python/helpers.rs(get_tz_name:return an empty string when the key is
None) would close that path andpreserve the local offset; I did not build the Rust extension (no cargo
on this machine) so that guard is not included here.
real offset. That matches the reporter's own workaround
(
pendulum.now('UTC')); preserving the offset needs the Rust guard above.Pull Request Check List
Fixes #989.