django-timezone-field icon indicating copy to clipboard operation
django-timezone-field copied to clipboard

System timezones or installed tzdata may not cover pytz.common_timezones

Open paulocoutinhox opened this issue 2 years ago • 5 comments

Hi,

Im getting this error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/paulo/Developer/workspaces/python/pyaa/manage.py", line 22, in <module>
    main()
  File "/Users/paulo/Developer/workspaces/python/pyaa/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 420, in execute
    django.setup()
  File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 304, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/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 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/paulo/Developer/workspaces/python/pyaa/customer/models.py", line 12, in <module>
    from timezone_field import TimeZoneField
  File "/usr/local/lib/python3.9/site-packages/timezone_field/__init__.py", line 1, in <module>
    from timezone_field.fields import TimeZoneField
  File "/usr/local/lib/python3.9/site-packages/timezone_field/fields.py", line 11, in <module>
    class TimeZoneField(models.Field):
  File "/usr/local/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 "/usr/local/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/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/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'

Thanks.

paulocoutinhox avatar Mar 11 '22 04:03 paulocoutinhox

I need install package tzdata to make it work.

It is really necessary?

paulocoutinhox avatar Mar 11 '22 04:03 paulocoutinhox

Hi @paulocoutinhox, what version of django are you running and on what platform?

It looks like django 4.X on windows should be installing tzdata by default. So I'm guessing you're on django 3.X on windows? Is that correct? Thanks.

mfogel avatar Mar 17 '22 16:03 mfogel

Im using latest django 4 on macos.

paulocoutinhox avatar Mar 17 '22 16:03 paulocoutinhox

Ok thanks

It looks like the timezone which is causing the problem is Pacific/Kanton was added to the IANA database in september 2021. So it makes sense that the system default list of timezones doesn't include it yet.

I'm hesitant to add a direct dependency on tzdata to this package because both python stdlib (via zoneinfo) and django choose not to do so. Let me mull it over. Perhaps we should push for django to remove the sys_platform == 'win32' part of this line.

mfogel avatar Mar 17 '22 17:03 mfogel

I just encountered the same issue with python 3.9 on debian bullseyse with django 3.x. I now manually fixed pytz==2021.1 for my setup to get around this.

garw avatar May 27 '22 22:05 garw