#36943: "Converter is already registered" incorrectly raised when registering a
malformed converter.
-------------------------------+---------------------------------------
     Reporter:  Austin Morton  |                     Type:  Bug
       Status:  new            |                Component:  Core (URLs)
      Version:  6.0            |                 Severity:  Normal
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+---------------------------------------
 Initialize an empty project
 {{{
 $ uv init . && uv add django && uv run django-admin startproject repro .

 Initialized project `django-repro` at `/Users/amorton/src/django-repro`
 Using CPython 3.14.0
 Creating virtual environment at: .venv
 Resolved 5 packages in 132ms
 Installed 3 packages in 97ms
  + asgiref==3.11.1
  + django==6.0.2
  + sqlparse==0.5.5
 }}}

 Edit urls.py to the following:
 {{{
 from django.urls import include, path, register_converter


 class MyConverter:
     # forgot to specify regex
     # regex = "[^/]+"

     def to_python(self, value):
         return value

     def to_url(self, value):
         return value


 register_converter(MyConverter, "mine")

 urlpatterns = [
     path("<mine:foo>", include([])),
 ]
 }}}

 Run the development server:
 {{{
 $ uv run manage.py runserver
 Watching for file changes with StatReloader
 Performing system checks...

 Exception in thread django-main-thread:
 Traceback (most recent call last):
    ...
   File "/Users/amorton/src/django-repro/repro/urls.py", line 15, in
 <module>
     register_converter(MyConverter, "mine")
     ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
   File "/Users/amorton/src/django-repro/.venv/lib/python3.14/site-
 packages/django/urls/converters.py", line 57, in register_converter
     raise ValueError(f"Converter {type_name!r} is already registered.")
 ValueError: Converter 'mine' is already registered.
 }}}

 What's going on here is that the original exception is being swallowed in
 django.utils.autoreload.BaseReloader.run.
 The exception gets thrown after the call to register_converter succeeds,
 but before the URLResolver.urlconf_module cached property returns.
 The urlconf module is executed a second time later, and the original
 exception is never shown to the user.

 Ultimately this was a user-error on my part, but was very difficult to
 debug.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36943>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019c8d2f687e-4dd42ece-86ef-4093-b212-6520588539f1-000000%40eu-central-1.amazonses.com.

Reply via email to