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

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

Closed
PieterL75 opened this issue Feb 18, 2022 · 5 comments
Closed

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

PieterL75 opened this issue Feb 18, 2022 · 5 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@PieterL75
Copy link
Contributor

PieterL75 commented Feb 18, 2022

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 ?

@PieterL75 PieterL75 added the type: bug A confirmed report of unexpected behavior in the application label Feb 18, 2022
@jeremystretch
Copy link
Member

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 jeremystretch added the beta Concerns a bug/feature in a beta release label Feb 18, 2022
@mmfreitas
Copy link

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...

@jeremystretch
Copy link
Member

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 jeremystretch self-assigned this Feb 18, 2022
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Feb 18, 2022
@gdvalderrama
Copy link

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.

@jeremystretch
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

4 participants