Opened 8 years ago
Last modified 5 years ago
#28911 closed Cleanup/optimization
Django dependency pytz does not recognize Msft time zone within Windows Subsystem for Linux — at Initial Version
| Reported by: | El'endia Starman | Owned by: | |
|---|---|---|---|
| Component: | Utilities | Version: | 1.11 |
| Severity: | Normal | Keywords: | timezone |
| Cc: | Sergey Fedoseev, Stephen James | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Under Windows Subsystem for Linux (I was using openSUSE), the only available time zone is Msft, which uses settings that are set on the Windows side. This is not a valid time zone in pytz. In the process of reporting an error thrown by a bug in my code, Django tried to normalize the time zone provided in the project settings by passing it through pytz. pytz then complains that the time zone is unknown. Somewhat amusingly, this error is also caught by Django and goes through the same code path, quickly hitting the recursion limit.
See below for a significant part of the stack trace. My temporary solution was to change
return pytz.timezone(settings.TIME_ZONE)
to
return pytz.timezone(settings.TIME_ZONE if settings.TIME_ZONE in pytz.all_timezones else 'UTC')
---
pytz.exceptions.UnknownTimeZoneError: 'Msft'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 43, in inner
response = response_for_exception(request, exc)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/views/debug.py", line 84, in technical_500_response
html = reporter.get_traceback_html()
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/views/debug.py", line 328, in get_traceback_html
return t.render(c)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 207, in render
return self._render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 1040, in render
output = self.filter_expression.resolve(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 732, in resolve
obj = template_localtime(obj, context.use_tz)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 195, in template_localtime
return localtime(value) if should_convert else value
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 213, in localtime
timezone = get_current_timezone()
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 97, in get_current_timezone
return getattr(_active, "value", get_default_timezone())
File "/home/elendiastarman/.virtualenvs/django/lib64/python3.4/functools.py", line 472, in wrapper
result = user_function(*args, **kwds)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 79, in get_default_timezone
return pytz.timezone(settings.TIME_ZONE)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/pytz/__init__.py", line 191, in timezone
raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'Msft'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.4/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
response = self.get_response(request)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 43, in inner
response = response_for_exception(request, exc)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/views/debug.py", line 84, in technical_500_response
html = reporter.get_traceback_html()
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/views/debug.py", line 328, in get_traceback_html
return t.render(c)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 207, in render
return self._render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 199, in _render
return self.nodelist.render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 990, in render
bit = node.render_annotated(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 957, in render_annotated
return self.render(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 1040, in render
output = self.filter_expression.resolve(context)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/template/base.py", line 732, in resolve
obj = template_localtime(obj, context.use_tz)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 195, in template_localtime
return localtime(value) if should_convert else value
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 213, in localtime
timezone = get_current_timezone()
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 97, in get_current_timezone
return getattr(_active, "value", get_default_timezone())
File "/home/elendiastarman/.virtualenvs/django/lib64/python3.4/functools.py", line 472, in wrapper
result = user_function(*args, **kwds)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/django/utils/timezone.py", line 79, in get_default_timezone
return pytz.timezone(settings.TIME_ZONE)
File "/home/elendiastarman/.virtualenvs/django/lib/python3.4/site-packages/pytz/__init__.py", line 191, in timezone
raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'Msft'