#4915: A smarter resolver: try to disambiguate URL patterns
--------------------------------------+-------------------------------------
          Reporter:  [EMAIL PROTECTED]  |         Owner:  mtredinnick
            Status:  new              |     Milestone:             
         Component:  Core framework   |       Version:  SVN        
        Resolution:                   |      Keywords:             
             Stage:  Accepted         |     Has_patch:  1          
        Needs_docs:  0                |   Needs_tests:  1          
Needs_better_patch:  1                |  
--------------------------------------+-------------------------------------
Comment (by semenov):

 If anybodes cares, I'm attaching the updated patch against [8461].

 See below the test cases.

 First, what happens with the trunk code:
 {{{
 #!python
     (r'^/profile/$', 'account.views.profile'),
     (r'^/profile/(?P<user>\d+)/', 'account.views.profile'),

 # ...

 django.core.urlresolvers.reverse('account.views.profile') # "/profile/"
 django.core.urlresolvers.reverse('account.views.profile', kwargs={'user':
 12345}) # "/profile/" - BUG!
 }}}

 and again with the trunk:
 {{{
 #!python
     (r'^/profile/(?P<user>\d+)/', 'account.views.profile'),
     (r'^/profile/$', 'account.views.profile'),

 # ...

 django.core.urlresolvers.reverse('account.views.profile', kwargs={'user':
 12345}) # "/profile/12345/"
 django.core.urlresolvers.reverse('account.views.profile') # throws
 NoReverseMatch - BUG!
 }}}

 With the patch, in both cases:
 {{{
 #!python
 django.core.urlresolvers.reverse('account.views.profile', kwargs={'user':
 12345}) # "/profile/12345/"
 django.core.urlresolvers.reverse('account.views.profile') # "/profile/"
 # and even:
 django.core.urlresolvers.reverse('account.views.profile', args=(12345,)) #
 "/profile/12345/"
 }}}

 The lookup algo complexity is still constant time.

 The patch is not perfect though:
 {{{
 #!python
     (r'^/list/(?P<user>\d+)/(?P<page>\d+)/', 'list.users'),

 # ...

 django.core.urlresolvers.reverse('list.users', kwargs={'user':123,
 'page':456}) # "/list/123/456/"
 django.core.urlresolvers.reverse('list.users', args=(123, 456,)) #
 "/list/123/456/"
 django.core.urlresolvers.reverse('list.users', args=(123,),
 kwargs={'page': 456}) # throws NoReverseMatch - BUG!
 }}}
 since it handles only two situations: when all named args are passed in
 ''kwargs'' (as expected), or when '''all''' named args are passed with
 ''args'' (trivial "fallback" behaviour).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4915#comment:11>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to