#27597: UrlResolver doesn't check all possibilities
------------------------------+--------------------------------------
Reporter: Adrien mille | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.10
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
------------------------------+--------------------------------------
Description changed by Adrien mille:
Old description:
> The UrlResolver doesn't check possibilities through multiple namespaces ;
> It'll look out for the viewname in a namespace to test all possibilities.
> But the resolver won't go backward to other namespaces to list additional
> possibilities that might match. I've few difficulties to define that
> issue so I join this test case to reproduce it.
>
> {{{
> from django.test import TestCase
> from django.conf.urls import url, include
> from django.shortcuts import reverse
>
> def my_view(**kwargs):
> pass
>
> class UrlConf(object):
> # those are url patterns and views that I can re-used multiple times
> common_url_patterns = [
> # this is a page like any others
> url(r'^$', my_view, name='page'),
> # here is a namespace to let's say group actions together
> # I clearly set a namespace to make it more logical
> url(r'^actions/', include([
> url(r'^action/$', my_view, name='action')
> ], namespace='actions'))
> ]
>
> urlpatterns = [
> # this is a part of my app into a namespace, nothing special
> about it
> url(r'^root/', include([
> # depending of what are my keyword arguments
> # I will use one of these two followings possibilities
> url(r'^without-context/', include(common_url_patterns),
> kwargs={'additional_arg': -21}),
> url(r'^with-context/(?P<var>[0-9]+)/',
> include(common_url_patterns))
> # you may ask why I'm not using nested optional argument
> # this is because I explicitly defined kwargs arguments for
> my view in one cases
> # but not in the other, so I cannot solve it that way
> ], namespace='root'))
> ]
>
> class TestUrlResolver(TestCase):
> def _test_reverse_for(self, viewname, kwargs, expected):
> self.assertEqual(reverse(viewname, kwargs=kwargs,
> urlconf=UrlConf), expected)
>
> def test_page_without_var(self):
> self._test_reverse_for('root:page', None, '/root/without-
> context/')
>
> def test_page_with_var(self):
> self._test_reverse_for('root:page', {'var': 42}, '/root/with-
> context/42/')
>
> def test_action_without_var(self):
> self._test_reverse_for('root:actions:action', None, '/root
> /without-context/actions/action/')
>
> def test_action_with_var(self):
> self._test_reverse_for('root:actions:action', {'var': 42}, '/root
> /with-context/42/actions/action/')
> }}}
New description:
The UrlResolver doesn't check possibilities through multiple namespaces ;
It'll look out for the viewname in a namespace to test all possibilities.
But the resolver won't go backward to other namespaces to list additional
possibilities that might match. I've few difficulties to define that issue
so I join this test case to reproduce it.
{{{
from django.test import TestCase
from django.conf.urls import url, include
from django.shortcuts import reverse
def my_view(**kwargs):
pass
class UrlConf(object):
app_name = 'myapp'
# those are url patterns and views that I can re-used multiple times
common_url_patterns = [
# this is a page like any others
url(r'^$', my_view, name='page'),
# here is a namespace to let's say group actions together
# I clearly set a namespace to make it more logical
url(r'^actions/', include(([
url(r'^action/$', my_view, name='action')
], app_name), namespace='actions'))
]
urlpatterns = [
# this is a part of my app into a namespace, nothing special about
it
url(r'^root/', include(([
# depending of what are my keyword arguments
# I will use one of these two followings possibilities
url(r'^without-context/', include(common_url_patterns),
kwargs={'additional_arg': -21}),
url(r'^with-context/(?P<var>[0-9]+)/',
include(common_url_patterns)),
# you may ask why I'm not using nested optional argument
# this is because I explicitly defined kwargs arguments for my
view in one cases
# but not in the other, so I cannot solve it that way
], app_name)))
]
class TestUrlResolver(TestCase):
def _test_reverse_for(self, viewname, kwargs, expected):
uri = reverse(viewname, kwargs=kwargs, urlconf=UrlConf)
self.assertEqual(uri, expected)
def test_page_without_var(self):
self._test_reverse_for('myapp:page', None, '/root/without-
context/')
def test_page_with_var(self):
self._test_reverse_for('myapp:page', {'var': 42}, '/root/with-
context/42/')
def test_action_without_var(self):
self._test_reverse_for('myapp:actions:action', None, '/root
/without-context/actions/action/')
def test_action_with_var(self):
self._test_reverse_for('myapp:actions:action', {'var': 42}, '/root
/with-context/42/actions/action/')
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27597#comment:2>
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/069.963d6ef42c59f485afa09373002d1c75%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.