#33674: Timezones cause 500 errors to not email the site admin
---------------------------------+--------------------------------------
Reporter: iragm | Owner: (none)
Type: Bug | Status: closed
Component: Error reporting | Version: 4.0
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by iragm):
tzinfo was not installed. I am not sure what to make of that, I would
have expected pip to install it. This is true both in my dev environment
which has always worked, and production, which only works when I add in
the try stuff:
Looks like we are now getting an error "Is a directory". I am going to
take a guess that NO timezone at all is being set by Daphne when an error
happens, which causes the path to go to the root folder rather than the
(for example) America folder and find the New_York file.
{{{
2022-05-04 08:19:20,317 ERROR Exception inside application: [Errno 21]
Is a directory: '/opt/production/lib/python3.9/site-
packages/tzdata/zoneinfo'
Traceback (most recent call last):
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
414, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "/usr/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
return await fut
File "/opt/production/lib/python3.9/site-
packages/asgiref/current_thread_executor.py", line 22, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
455, in thread_handler
return func(*args, **kwargs)
File "/opt/production/lib/python3.9/site-
packages/django/views/generic/base.py", line 84, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/production/fishauctions/./auctions/views.py", line 2245, in
dispatch
raise UnknownError()
NameError: name 'UnknownError' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/opt/production/lib/python3.9/site-
packages/django/utils/deprecation.py", line 150, in __acall__
response = response or await self.get_response(request)
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 44, in inner
response = await sync_to_async(
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
414, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "/usr/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
return await fut
File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
453, in thread_handler
return func(*args, **kwargs)
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 139, in
response_for_exception
response = handle_uncaught_exception(
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 184, in
handle_uncaught_exception
return callback(request)
File "/opt/production/lib/python3.9/site-
packages/django/utils/decorators.py", line 133, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/production/lib/python3.9/site-
packages/django/views/defaults.py", line 102, in server_error
return HttpResponseServerError(template.render())
File "/opt/production/lib/python3.9/site-
packages/django/template/backends/django.py", line 62, in render
return self.template.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 175, in render
return self._render(context)
File "/opt/production/lib/python3.9/site-packages/django/test/utils.py",
line 111, in instrumented_test_render
return self.nodelist.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in render
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 958, in render_annotated
return self.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
File "/opt/production/lib/python3.9/site-packages/django/test/utils.py",
line 111, in instrumented_test_render
return self.nodelist.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in render
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 958, in render_annotated
return self.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/templatetags/tz.py", line 145, in render
with timezone.override(self.tz.resolve(context)):
File "/opt/production/lib/python3.9/site-
packages/django/utils/timezone.py", line 157, in __enter__
activate(self.timezone)
File "/opt/production/lib/python3.9/site-
packages/django/utils/timezone.py", line 121, in activate
_active.value = zoneinfo.ZoneInfo(timezone)
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 91, in
open_binary
return reader.open_resource(resource)
File "<frozen importlib._bootstrap_external>", line 1055, in
open_resource
IsADirectoryError: [Errno 21] Is a directory:
'/opt/production/lib/python3.9/site-packages/tzdata/zoneinfo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/opt/production/lib/python3.9/site-
packages/django/utils/deprecation.py", line 150, in __acall__
response = response or await self.get_response(request)
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 44, in inner
response = await sync_to_async(
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
414, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "/usr/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
return await fut
File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/production/lib/python3.9/site-packages/asgiref/sync.py", line
453, in thread_handler
return func(*args, **kwargs)
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 139, in
response_for_exception
response = handle_uncaught_exception(
File "/opt/production/lib/python3.9/site-
packages/django/core/handlers/exception.py", line 184, in
handle_uncaught_exception
return callback(request)
File "/opt/production/lib/python3.9/site-
packages/django/utils/decorators.py", line 133, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/production/lib/python3.9/site-
packages/django/views/defaults.py", line 102, in server_error
return HttpResponseServerError(template.render())
File "/opt/production/lib/python3.9/site-
packages/django/template/backends/django.py", line 62, in render
return self.template.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 175, in render
return self._render(context)
File "/opt/production/lib/python3.9/site-packages/django/test/utils.py",
line 111, in instrumented_test_render
return self.nodelist.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in render
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 958, in render_annotated
return self.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
File "/opt/production/lib/python3.9/site-packages/django/test/utils.py",
line 111, in instrumented_test_render
return self.nodelist.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in render
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 1000, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in
self]))
File "/opt/production/lib/python3.9/site-
packages/django/template/base.py", line 958, in render_annotated
return self.render(context)
File "/opt/production/lib/python3.9/site-
packages/django/templatetags/tz.py", line 145, in render
with timezone.override(self.tz.resolve(context)):
File "/opt/production/lib/python3.9/site-
packages/django/utils/timezone.py", line 157, in __enter__
activate(self.timezone)
File "/opt/production/lib/python3.9/site-
packages/django/utils/timezone.py", line 121, in activate
_active.value = zoneinfo.ZoneInfo(timezone)
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 91, in
open_binary
return reader.open_resource(resource)
File "<frozen importlib._bootstrap_external>", line 1055, in
open_resource
IsADirectoryError: [Errno 21] Is a directory:
'/opt/production/lib/python3.9/site-packages/tzdata/zoneinfo'
During handling of the above exception, another exception occurred:
}}}
The time zone is supposed to be set via a cookie in my base.html file. My
settings look like this:
{{{
TIME_ZONE = os.environ['TIME_ZONE']
# this is set correctly to: 'America/New_York'
USE_I18N = False
USE_L10N = False
USE_TZ = True
}}}
At the top of base.html:
{{{
{% load tz %}
{% load l10n %}
{% timezone user_timezone %}
}}}
And user_timezone is set by a context processor:
{{{
def add_tz(request):
"""
Add timezone cookie - example: 'America/New_York'
This is set via js with
Intl.DateTimeFormat().resolvedOptions().timeZone
"""
user_timezone = ""
user_timezone_set = False
try:
if request.COOKIES['user_timezone']:
user_timezone = request.COOKIES['user_timezone']
user_timezone_set = True
except:
pass
if not user_timezone:
user_timezone = "America/Chicago"
user_timezone_set = False
return {'user_timezone': user_timezone, 'user_timezone_set':
user_timezone_set}
}}}
I believe this context processor is not getting called when the 500 error
occurs, so user_timezone is probably either None or an empty string. So
that could be the issue.
One of the things that I like about Django is that when I do something
stupid it tells me in the form of the error email - that should happen
even if the {% timezone user_timezone %} tag is not set correctly, right?
--
Ticket URL: <https://code.djangoproject.com/ticket/33674#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701808f17634d-43f7550e-124b-4503-a009-5f062f453fb3-000000%40eu-central-1.amazonses.com.