Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crashing on importing localtime when TZ is malformed #1100

Merged
merged 1 commit into from
Jul 23, 2024
Merged

Conversation

akx
Copy link
Member

@akx akx commented Jul 17, 2024

Fixes #1092.

When pytz is not installed, importing babel.localtime could fail (repeatedly) when the TZ environment variable is malformed enough to be caught by _validate_tzfile_path, which might throw a certain ValueError.

(When pytz is installed, it would raise the same pytz.exceptions.UnknownTimeZoneError we already catch and ignore for the same input.)

@akx akx marked this pull request as ready for review July 17, 2024 15:28
@akx akx added this to the Babel 2.16 milestone Jul 18, 2024
…rmed

When `pytz` is _not_ installed, importing `babel.localtime` could fail
(repeatedly) when the `TZ` environment variable is malformed enough to be
caught by `_validate_tzfile_path`, which might throw a certain `ValueError`.

(When `pytz` is installed, it would raise an `UnknownTimeZoneError` we
already catch and ignore for the same sort of input.)

Fixes #1092
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.28%. Comparing base (2f87363) to head (ff4c01c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1100      +/-   ##
==========================================
+ Coverage   91.09%   91.28%   +0.19%     
==========================================
  Files          26       26              
  Lines        4470     4476       +6     
==========================================
+ Hits         4072     4086      +14     
+ Misses        398      390       -8     
Flag Coverage Δ
macos-12-3.10 90.03% <66.66%> (+0.12%) ⬆️
macos-12-3.11 90.03% <66.66%> (+0.12%) ⬆️
macos-12-3.12 90.32% <66.66%> (+0.12%) ⬆️
macos-12-3.8 90.02% <50.00%> (+0.19%) ⬆️
macos-12-3.9 90.02% <66.66%> (+0.12%) ⬆️
macos-12-pypy3.10 90.03% <66.66%> (+0.12%) ⬆️
ubuntu-22.04-3.10 90.05% <66.66%> (+0.12%) ⬆️
ubuntu-22.04-3.11 90.05% <66.66%> (+0.12%) ⬆️
ubuntu-22.04-3.12 90.34% <66.66%> (+0.12%) ⬆️
ubuntu-22.04-3.8 90.05% <50.00%> (+0.19%) ⬆️
ubuntu-22.04-3.9 90.05% <66.66%> (+0.12%) ⬆️
ubuntu-22.04-pypy3.10 90.05% <66.66%> (+0.12%) ⬆️
windows-2022-3.10 90.18% <16.66%> (-0.10%) ⬇️
windows-2022-3.11 90.18% <16.66%> (-0.10%) ⬇️
windows-2022-3.12 90.47% <16.66%> (-0.10%) ⬇️
windows-2022-3.8 90.17% <50.00%> (-0.04%) ⬇️
windows-2022-3.9 90.17% <16.66%> (-0.10%) ⬇️
windows-2022-pypy3.10 90.18% <16.66%> (-0.10%) ⬇️

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.

@@ -19,6 +23,16 @@ def _get_tzinfo(tzenv: str):
else:

Choose a reason for hiding this comment

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

as zoneinfo may be None, should we check for that here?

Copy link
Member Author

Choose a reason for hiding this comment

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

pytz is a required dep when Python < 3.9; zoneinfo should be available >= 3.9...

@matthiashuschle
Copy link

Looks good to me.

@akx akx merged commit ad0fabe into master Jul 23, 2024
23 checks passed
@akx akx deleted the issue-1092 branch July 23, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ValueError from failed import of localtime submodule
2 participants