#29775: custom url converters are not picked up on reverse when part of included
patterns with namespace
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  nobody
  ericbrandwein                      |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  2.1
  (URLs)                             |       Keywords:  converter,
               Severity:  Normal     |  namespace, reverse, include
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Under normal circumstances, url converters `to_url` methods are called
 when reversing a url, however, this behavior is inconsistent when used
 with included sub-patterns, when these sub-patterns have themselves
 included sub-patterns with a namespace assigned.

 To demonstrate:
 {{{
 from django.urls import path, include, register_converter
 from django.urls.converters import StringConverter


 class ReverseStringConverter(StringConverter):
     """More complex use cases are possible, but this simple case of
 reversing the string already shows it in effect"""
     def to_python(self, value):
         return value[::-1]

     def to_url(self, value):
         return value[::-1]


 # We just want to test the reverse()
 def noop(request, **kwargs):
     pass


 register_converter(ReverseStringConverter, 'reverse')

 second_layer_urlpatterns = [
     path('', noop, name='failure-view'),
 ]

 first_layer_urlpatterns = [
     path('', include(
         (second_layer_urlpatterns, 'app_name'), namespace='ns')),
     path('', include(second_layer_urlpatterns)),
     path('', noop, name='success-view'),
 ]

 urlpatterns = [
     path('<reverse:param>/', include(first_layer_urlpatterns)),
 ]

 }}}

 When running the following test, reverse works fine when reversing
 `failure-view` or `success-view`, but not when reversing `ns:failure-
 view`:

 {{{
 >>> from django.urls import reverse
 >>> reverse('failure-view', args=['foo'])
 '/oof/'
 >>> reverse('ns:failure-view', args=['foo'])
 '/foo/'
 >>> reverse('success-view', args=['foo'])
 '/oof/'
 }}}

 It probably is very similar to #29415. I tested it in version 2.1.1.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29775>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.3e50fa36204138f282b9c7390aee7b66%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to