Re: [Django] #36943: Autoreloader hides exceptions from urlconf module (was: "Converter is already registered" incorrectly raised when registering a malformed converter.)

0 views
Skip to first unread message

Django

unread,
Feb 25, 2026, 3:33:04 PM (19 hours ago) Feb 25
to django-...@googlegroups.com
#36943: Autoreloader hides exceptions from urlconf module
--------------------------------------+------------------------------------
Reporter: Austin Morton | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Utilities | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* component: Core (URLs) => Utilities
* stage: Unreviewed => Accepted
* summary:
"Converter is already registered" incorrectly raised when registering
a malformed converter.
=> Autoreloader hides exceptions from urlconf module
* type: Bug => Cleanup/optimization

Comment:

Thanks for the report. We could at least include the original error in the
cause without altering the behavior.

Something like this looks promising, would you like to polish and submit a
PR?

{{{#!diff
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 99812979d7..9e5edaee57 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -33,6 +33,8 @@ logger = logging.getLogger("django.utils.autoreload")
# file paths to allow watching them in the future.
_error_files = []
_exception = None
+# A nice comment.
+_url_module_exception = None

try:
import termios
@@ -62,7 +64,7 @@ def check_errors(fn):
global _exception
try:
fn(*args, **kwargs)
- except Exception:
+ except Exception as e:
_exception = sys.exc_info()

et, ev, tb = _exception
@@ -75,8 +77,10 @@ def check_errors(fn):

if filename not in _error_files:
_error_files.append(filename)
+ if _url_module_exception is not None:
+ raise e from _url_module_exception

- raise
+ raise e

return wrapper

@@ -339,6 +343,7 @@ class BaseReloader:
return False

def run(self, django_main_thread):
+ global _url_module_exception
logger.debug("Waiting for apps ready_event.")
self.wait_for_apps_ready(apps, django_main_thread)
from django.urls import get_resolver
@@ -347,10 +352,10 @@ class BaseReloader:
# reloader starts by accessing the urlconf_module property.
try:
get_resolver().urlconf_module
- except Exception:
+ except Exception as e:
# Loading the urlconf can result in errors during
development.
- # If this occurs then swallow the error and continue.
- pass
+ # If this occurs then store the error and continue.
+ _url_module_exception = e
logger.debug("Apps ready_event triggered. Sending
autoreload_started signal.")
autoreload_started.send(sender=self)
self.run_loop()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36943#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages