tzdata error when upgrading from 3.1 to 3.2-beta1 #6117

Closed
opened 2025-12-29 19:36:56 +01:00 by adam · 5 comments
Owner

Originally created by @PieterL75 on GitHub (Feb 18, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.2-beta1

Python version

3.9

Steps to Reproduce

Upgrade from 3.1 to 3.2-beta1

Expected Behavior

smooth upgrade

Observed Behavior

An error was thrown related to 'tzdata'

Applying database migrations (python3 netbox/manage.py migrate)...
Traceback (most recent call last):
File "/usr/lib/python3.9/zoneinfo/_common.py", line 12, in load_tzdata
return importlib.resources.open_binary(package_name, resource_name)
File "/usr/lib/python3.9/importlib/resources.py", line 88, in open_binary
package = _get_package(package)
File "/usr/lib/python3.9/importlib/resources.py", line 49, in _get_package
module = _resolve(package)
File "/usr/lib/python3.9/importlib/resources.py", line 40, in _resolve
return import_module(name)
File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 972, in _find_and_load_unlocked
File "", line 228, in _call_with_frames_removed
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 972, in _find_and_load_unlocked
File "", line 228, in _call_with_frames_removed
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tzdata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/netbox/netbox/manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/init.py", line 425, in execute_from_command_line
utility.execute()
File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/init.py", line 401, in execute
django.setup()
File "/opt/netbox/venv/lib/python3.9/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/netbox/venv/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/opt/netbox/venv/lib/python3.9/site-packages/django/apps/config.py", line 223, in create
import_module(entry)
File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 790, in exec_module
File "", line 228, in _call_with_frames_removed
File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/init.py", line 1, in
from timezone_field.fields import TimeZoneField
File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 11, in
class TimeZoneField(models.Field):
File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 41, in TimeZoneField
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones]
File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 41, in
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones]
File "/usr/lib/python3.9/zoneinfo/_common.py", line 24, in load_tzdata
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Pacific/Kanton'

@tobiasge mention :

Tobias Genannt 9 minutes ago
With Django 4 the default timezone implementation was changed.
You need to to install tzdata in your virtual environment:
pip install tzdata

After adding the tzdata to my local requirements, did not errorer anymore.

Probably the 'tzdata' has to be added to the base_requirements.txt ?

Originally created by @PieterL75 on GitHub (Feb 18, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.2-beta1 ### Python version 3.9 ### Steps to Reproduce Upgrade from 3.1 to 3.2-beta1 ### Expected Behavior smooth upgrade ### Observed Behavior An error was thrown related to 'tzdata' > Applying database migrations (python3 netbox/manage.py migrate)... > Traceback (most recent call last): > File "/usr/lib/python3.9/zoneinfo/_common.py", line 12, in load_tzdata > return importlib.resources.open_binary(package_name, resource_name) > File "/usr/lib/python3.9/importlib/resources.py", line 88, in open_binary > package = _get_package(package) > File "/usr/lib/python3.9/importlib/resources.py", line 49, in _get_package > module = _resolve(package) > File "/usr/lib/python3.9/importlib/resources.py", line 40, in _resolve > return import_module(name) > File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module > return _bootstrap._gcd_import(name[level:], package, level) > File "<frozen importlib._bootstrap>", line 1030, in _gcd_import > File "<frozen importlib._bootstrap>", line 1007, in _find_and_load > File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked > File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed > File "<frozen importlib._bootstrap>", line 1030, in _gcd_import > File "<frozen importlib._bootstrap>", line 1007, in _find_and_load > File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked > File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed > File "<frozen importlib._bootstrap>", line 1030, in _gcd_import > File "<frozen importlib._bootstrap>", line 1007, in _find_and_load > File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked > ModuleNotFoundError: No module named 'tzdata' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/opt/netbox/netbox/manage.py", line 10, in <module> > execute_from_command_line(sys.argv) > File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line > utility.execute() > File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute > django.setup() > File "/opt/netbox/venv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup > apps.populate(settings.INSTALLED_APPS) > File "/opt/netbox/venv/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate > app_config = AppConfig.create(entry) > File "/opt/netbox/venv/lib/python3.9/site-packages/django/apps/config.py", line 223, in create > import_module(entry) > File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module > return _bootstrap._gcd_import(name[level:], package, level) > File "<frozen importlib._bootstrap>", line 1030, in _gcd_import > File "<frozen importlib._bootstrap>", line 1007, in _find_and_load > File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked > File "<frozen importlib._bootstrap>", line 680, in _load_unlocked > File "<frozen importlib._bootstrap_external>", line 790, in exec_module > File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed > File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/__init__.py", line 1, in <module> > from timezone_field.fields import TimeZoneField > File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 11, in <module> > class TimeZoneField(models.Field): > File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 41, in TimeZoneField > default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] > File "/opt/netbox/venv/lib/python3.9/site-packages/timezone_field/fields.py", line 41, in <listcomp> > default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] > File "/usr/lib/python3.9/zoneinfo/_common.py", line 24, in load_tzdata > raise ZoneInfoNotFoundError(f"No time zone found with key {key}") > zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Pacific/Kanton' @tobiasge mention : > [Tobias Genannt](https://app.slack.com/team/U01QEG4SFMW) [9 minutes ago](https://netdev-community.slack.com/archives/C01P0FRSXRV/p1645180997892189?thread_ts=1645180110.952929&cid=C01P0FRSXRV) > With Django 4 the default timezone implementation was changed. > You need to to install tzdata in your virtual environment: > pip install tzdata After adding the tzdata to my local requirements, did not errorer anymore. Probably the 'tzdata' has to be added to the base_requirements.txt ?
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 19:36:56 +01:00
adam closed this issue 2025-12-29 19:36:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 18, 2022):

I haven't seen this at all on Python 3.8; it seems to be related to the zoneinfo library under Python 3.9 and later:

By default, zoneinfo uses the system’s time zone data if available; if no system time zone data is available, the library will fall back to using the first-party tzdata package available on PyPI.

Still, even our CI tests under Python3.9 don't trigger any errors. Are you sure the environment was built correctly?

@jeremystretch commented on GitHub (Feb 18, 2022): I haven't seen this at all on Python 3.8; it seems to be related to the [`zoneinfo`](https://docs.python.org/3.9/library/zoneinfo.html) library under Python 3.9 and later: > By default, [zoneinfo](https://docs.python.org/3.9/library/zoneinfo.html#module-zoneinfo) uses the system’s time zone data if available; if no system time zone data is available, the library will fall back to using the first-party [tzdata](https://pypi.org/project/tzdata/) package available on PyPI. Still, even our CI tests under Python3.9 don't trigger any errors. Are you sure the environment was built correctly?
Author
Owner

@mmfreitas commented on GitHub (Feb 18, 2022):

I've ran into this issue as well, while running upgrade.sh in the feature branch. I am also using Python3.9, the issue was resolved by putting 'tzdata' into the local_requirements...

@mmfreitas commented on GitHub (Feb 18, 2022): I've ran into this issue as well, while running upgrade.sh in the feature branch. I am also using Python3.9, the issue was resolved by putting 'tzdata' into the local_requirements...
Author
Owner

@jeremystretch commented on GitHub (Feb 18, 2022):

Interesting; thanks for the confirmation. I wonder why django-timezone-field doesn't pull in tzdata automatically.

At any rate, depending on it directly seems like a reasonable solution, at lease for now. I still need to muddle through the change from pytz to zoneinfo in Django 4.0.

Aren't timezones fun?

@jeremystretch commented on GitHub (Feb 18, 2022): Interesting; thanks for the confirmation. I wonder why `django-timezone-field` doesn't pull in `tzdata` automatically. At any rate, depending on it directly seems like a reasonable solution, at lease for now. I still need to muddle through the change from `pytz` to `zoneinfo` in Django 4.0. Aren't timezones fun?
Author
Owner

@gdvalderrama commented on GitHub (Feb 21, 2022):

Just wanted to comment I've just had this same issue.

python 3.9.10
from django-timezone-field version 4.1.2
to django-timezone-field version 5.0

Guess I'll add tzdata to my dependencies meanwhile.

@gdvalderrama commented on GitHub (Feb 21, 2022): Just wanted to comment I've just had this same issue. python 3.9.10 from django-timezone-field version 4.1.2 to django-timezone-field version 5.0 Guess I'll add tzdata to my dependencies meanwhile.
Author
Owner

@jeremystretch commented on GitHub (Feb 23, 2022):

Here's a relevant bug report for django-timezone-field. It looks like tzdata may become a dependency of that project, but for now I'll just add tzdata as a direct dependency for NetBox.

@jeremystretch commented on GitHub (Feb 23, 2022): Here's a relevant [bug report](https://github.com/mfogel/django-timezone-field/issues/82) for `django-timezone-field`. It looks like `tzdata` may become a dependency of that project, but for now I'll just add `tzdata` as a direct dependency for NetBox.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6117