#34451: Incorrect exception handling within the django exception handler
--------------------------------+--------------------------------------
Reporter: Michael Galler | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Michael Galler):
* status: closed => new
* resolution: invalid =>
Comment:
After some digging I am sure that this is a django problem.
The problem also occurs in wsgi mode, tested with waitress.
The devserver already does several checks before it starts which are not
done by asgi/wsgi handlers.
These checks already detect the problem and prevent the start of the http
server.
if i disable the checks in the following file
venv/Lib/site-packages/django/core/management/base.py
{{{
def check(
self,
app_configs=None,
tags=None,
display_num_errors=False,
include_deployment_checks=False,
fail_level=checks.ERROR,
databases=None,
):
"""
Use the system check framework to validate entire Django project.
Raise CommandError for any serious message (error or critical
errors).
If there are only light messages (like warnings), print them to
stderr
and don't raise an exception.
"""
return
}}}
Now the devserver behaves the same way
{{{
File "C:\code\myproject\venv\Lib\site-
packages\django\core\handlers\base.py", line 141, in get_response
response = self._middleware_chain(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\core\handlers\exception.py", line 58, in inner
response = response_for_exception(request, exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\core\handlers\exception.py", line 141, in
response_for_exception
response = handle_uncaught_exception(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\core\handlers\exception.py", line 185, in
handle_uncaught_exception
callback = resolver.resolve_error_handler(500)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\urls\resolvers.py", line 729, in resolve_error_handler
callback = getattr(self.urlconf_module, "handler%s" % view_type, None)
^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\utils\functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "C:\code\myproject\venv\Lib\site-
packages\django\urls\resolvers.py", line 708, in urlconf_module
return import_module(self.urlconf_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\importlib\__init__.py", line 126,
in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in
_call_with_frames_removed
File "C:\code\myproject\myproject\urls.py", line 10, in <module>
path('test/', TestView.as_view()),
}}}
If I interpret this correctly, the problem is that the exception handler
tries to render the 500 page, which imports the urls which leads to the
same error.
The exception handler seems to have problems when it causes exceptions
itself :D
--
Ticket URL: <https://code.djangoproject.com/ticket/34451#comment:4>
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/01070187378a210e-cecad733-56f7-4c38-94c7-5bbacbb3a34a-000000%40eu-central-1.amazonses.com.