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

5.0 - No time zone found with key Pacific/Kanto #82

Closed
M3te0r opened this issue Feb 9, 2022 · 4 comments
Closed

5.0 - No time zone found with key Pacific/Kanto #82

M3te0r opened this issue Feb 9, 2022 · 4 comments

Comments

@M3te0r
Copy link

M3te0r commented Feb 9, 2022

Hi, I just upgraded to django-timezone-field 5.0 and have the migrations failing on DB + Tables creation
Django : 4.0.2
Python : 3.10.0
Using official 3.10-slim-bullseye docker image
Model code :

class UserProfile(Model):

    user = OneToOneField(
        User,
        on_delete=CASCADE,
        related_name="profile",
        verbose_name=_("Utilisateur"),
    )
    timezone = TimeZoneField(
        _("Fuseau horaire"),
        default="Europe/Paris",
        choices_display="WITH_GMT_OFFSET",
    )

Traceback :

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 12, in load_tzdata
    return importlib.resources.open_binary(package_name, resource_name)
  File "/usr/local/lib/python3.10/importlib/resources.py", line 43, in open_binary
    package = _common.get_package(package)
  File "/usr/local/lib/python3.10/importlib/_common.py", line 66, in get_package
    resolved = resolve(package)
  File "/usr/local/lib/python3.10/importlib/_common.py", line 57, in resolve
    return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, 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/app/manage.py", line 31, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 401, in execute
    django.setup()
  File "/opt/venv/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/venv/lib/python3.10/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/opt/venv/lib/python3.10/site-packages/django/apps/config.py", line 300, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/app/nova/users/models.py", line 19, in <module>
    from timezone_field import TimeZoneField
  File "/opt/venv/lib/python3.10/site-packages/timezone_field/__init__.py", line 1, in <module>
    from timezone_field.fields import TimeZoneField
  File "/opt/venv/lib/python3.10/site-packages/timezone_field/fields.py", line 11, in <module>
    class TimeZoneField(models.Field):
  File "/opt/venv/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in TimeZoneField
    default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones]
  File "/opt/venv/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in <listcomp>
    default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones]
  File "/usr/local/lib/python3.10/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'
@M3te0r
Copy link
Author

M3te0r commented Feb 9, 2022

From python zone info doc
https://docs.python.org/3/library/zoneinfo.html

The zoneinfo module provides a concrete time zone implementation to support the IANA time zone database as originally specified in PEP 615. 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.

I had to explicitly add tzdata to my project dependencies, closing the issue

@M3te0r M3te0r closed this as completed Feb 9, 2022
@squio
Copy link

squio commented Feb 9, 2022

Had the exact same issue:

  • Django 4.0.2
  • Python 3.10.2
  • error: No time zone found with key Pacific/Kanton

And pip install tzdata did work

Maybe add this to documentation in upgrade instructions?

@mfogel
Copy link
Owner

mfogel commented Feb 9, 2022 via email

mfogel added a commit that referenced this issue Feb 9, 2022
@sshishov
Copy link

Got the same issue, I guess you should add this dependency as an optional like django-timezone-field[tzdata] or similar. SO thread here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants