pytz includes a hard coded list of time zone names
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pytz |
New
|
Unknown
|
|||
python-tz (Ubuntu) |
Fix Released
|
Medium
|
Unassigned | ||
Jammy |
Fix Released
|
Undecided
|
Unassigned | ||
Kinetic |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[ Impact ]
The Debian/Ubuntu packages of pytz include a patch to not install pytz's zoneinfo database and instead load data from the system zoneinfo database. This keeps pytz up to date when system timezone updates are installed which is generally a good idea.
The pytz/__init__.py includes common_timezones and all_timezones lists, which enumerate the time zones in the database pytz was released with. If pytz is instead using the system database, these lists may not be correct (e.g. missing newly added time zones).
all_timezones and common_timezones should be calculated at run time. all_timezones will need to use os.walk to discover what timezones exist. common_timezones should be loaded from zone.tab, plus a hard coded list of extras such as UTC and US/Eastern.
Everytime a new timezone is added to tzdata in an update, this timezone cannot be used in pytz with the hardcoded list of timezones. For jammy and kinetic this applies to America/
* America/
* America/Nuuk
* Asia/Qostanay
* Europe/Kyiv
* Pacific/Kanton
[ Test Plan ]
Two autopkgtest test cases were added:
1. Run the upstream unittests
2. Regression tests with all tests that I could come up with.
There are no manual test, because all those test should also be run when there is a tzdata update to prevent regressions.
To manually test, a newly added timezone to tzdata should be able to be specified:
```
#!/usr/bin/python3
import pytz
pytz.timezone(
```
This should not raise UnknownTimeZone
[ Where problems could occur ]
Dynamically determine the timezones relies on a correct environment and can fail more easily if the environment is broken. python-tz is used in several places (maybe in the installer). The patch might have a performance impact, because the list of timezones is determined completely (but only once) instead of constructing it lazy.
[ Other Info ]
Upstream recommend our approach: https:/
description: | updated |
Changed in python-tz (Ubuntu): | |
status: | New → Confirmed |
importance: | Undecided → Medium |
Changed in pytz: | |
importance: | Medium → Unknown |
status: | Fix Released → Unknown |
Changed in pytz: | |
status: | Unknown → New |
tags: | added: rls-ll-incoming |
tags: | added: fr-2987 |
tags: | removed: rls-ll-incoming |
Changed in python-tz (Ubuntu): | |
status: | Confirmed → Fix Committed |
description: | updated |
tags: | added: patch |
description: | updated |
description: | updated |
common_timezones uses data not found in the binary database, so we may not be able to fix this in pytz. Worst case we need to provide a mechanism for distributions that package pytz in this way to keep this list up to date or dynamically generate it from distro specific sources.