Title: fix(tz): default to UTC when /etc/localtime is a bare zoneinfo copy by faresrafat3 · Pull Request #1079 · python-pendulum/pendulum · GitHub
Open Graph Title: fix(tz): default to UTC when /etc/localtime is a bare zoneinfo copy by faresrafat3 · Pull Request #1079 · python-pendulum/pendulum
X Title: fix(tz): default to UTC when /etc/localtime is a bare zoneinfo copy by faresrafat3 · Pull Request #1079 · python-pendulum/pendulum
Description: Summary pendulum.now() crashed with TypeError: 'None' is not an instance of 'str' when /etc/localtime is a bare copy of a zoneinfo file (minimal containers, Slurm jobs). _get_unix_timezone returned a Timezone whose key is None, and the Rust precise_diff helper assumed the key is a str. Root cause: _get_unix_timezone falls through to Timezone.from_file(f) when no named configuration is found. A zoneinfo file without an IANA key yields a Timezone with key is None. precise_diff then calls get_tz_name, which casts that None to PyString and raises. Verification $ python3.12 -c "import pendulum; from io import BytesIO; import pendulum.tz.timezone as t; d=open('/tmp/scratchpad/pendulum-src/tests/fixtures/tz/Paris','rb').read(); tz=t.Timezone.from_file(BytesIO(d)); a=pendulum.now(tz); b=pendulum.now(tz); print(b-a)" TypeError: 'None' is not an instance of 'str' $ PYTHONPATH=src python3.12 -m pytest tests/tz/ -q 641 passed, 3 skipped, 1 warning Fix When the bare-file fallback yields a keyless Timezone, fall through to the existing UTC default (with the existing warning) instead of returning it. Timezone.from_file itself still allows a keyless result for pickling and utcoffset use, so test_from_file_without_a_key_can_be_pickled still passes. _tz_from_env now passes the file path as the key so that path never produces a keyless Timezone. New test test_unix_localtime_regular_file_defaults_to_utc builds a root with /etc/localtime as a regular file and asserts the resolver returns a named (UTC) timezone. Against the unfixed code this test fails (resolver returns the keyless Timezone). What I did not verify Timezone.from_file(f) called directly with no key still produces a keyless Timezone; precise_diff against it still crashes in the Rust extension. 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 and preserve the local offset; I did not build the Rust extension (no cargo on this machine) so that guard is not included here. The change makes the Slurm case report UTC rather than the container's real offset. That matches the reporter's own workaround (pendulum.now('UTC')); preserving the offset needs the Rust guard above. Pull Request Check List Added tests for changed code. Updated documentation for changed code. Fixes #989.
Open Graph Description: Summary pendulum.now() crashed with TypeError: 'None' is not an instance of 'str' when /etc/localtime is a bare copy of a zoneinfo file (minimal containers, Slurm jobs). _get_unix_t...
X Description: Summary pendulum.now() crashed with TypeError: 'None' is not an instance of 'str' when /etc/localtime is a bare copy of a zoneinfo file (minimal containers, Slurm jo...
Opengraph URL: https://github.com/python-pendulum/pendulum/pull/1079
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b586ba16-ca4d-fe15-d13e-a2157a96728a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B6A2:12F061:148EF3:1CD885:6B046FD1 |
| html-safe-nonce | 246ce3447741aa0aac20e035a38f6e684678cd8274f911f3565dc1846168de71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkEyOjEyRjA2MToxNDhFRjM6MUNEODg1OjZCMDQ2RkQxIiwidmlzaXRvcl9pZCI6IjcyODI5NjEyMTkzOTU1NDcwODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3f1240a854711d08a8a3cae39900c39df8357ead1099a5db20cb2497d33d6f46 |
| hovercard-subject-tag | pull_request:5119796260 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/pull/1079/files |
| twitter:image | https://avatars.githubusercontent.com/u/214850337?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/214850337?s=400&v=4 |
| og:image:alt | Summary pendulum.now() crashed with TypeError: 'None' is not an instance of 'str' when /etc/localtime is a bare copy of a zoneinfo file (minimal containers, Slurm jobs). _get_unix_t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width