-
Notifications
You must be signed in to change notification settings - Fork 438
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
Conversation
…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
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -19,6 +23,16 @@ def _get_tzinfo(tzenv: str): | |||
else: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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...
Looks good to me. |
Fixes #1092.
When
pytz
is not installed, importingbabel.localtime
could fail (repeatedly) when theTZ
environment variable is malformed enough to be caught by_validate_tzfile_path
, which might throw a certainValueError
.(When
pytz
is installed, it would raise the samepytz.exceptions.UnknownTimeZoneError
we already catch and ignore for the same input.)