[Django] #24904: reverse() doesn't allow for nested current_app namespaces

33 views
Skip to first unread message

Django

unread,
Jun 3, 2015, 8:50:44 AM6/3/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+--------------------
Reporter: knbk | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
`reverse()` doesn't split the `current_app` on `:` like it does for
namespaces in the `viewname`. It directly compares a single namespace
"level" to the full `current_app` variable. Take the following urlconf:

{{{
blog_patterns = [
url(r'^comments-one/', include('comments.urls', 'comments-one',
'comments')),
url(r'^comments-two/', include('comments.urls', 'comments-two',
'comments')),
]

urlpatterns = [
url(r'^blog-one/', include(blog_patterns, 'blog-one', 'blog')),
url(r'^blog-two/', include(blog_patterns, 'blog-two', 'blog')),
]
}}}

To reverse urls for `blog-one:comments-one`, without hard-coding the
instance namespace in `viewname`, you might assume this would work:

{{{
reverse('blog:comments:view_name', current_app='blog-one:comments-one')
}}}

However, `'blog-one:comments-one'` doesn't compare equal to either
`'blog-one'` or `'comments-one'`, so it will use the default namespace for
each namespace nesting level instead, and return `/blog-two/comments-
two/...`.

This also means that this example in the docs won't work for nested
namespaces:

{{{
def render_to_response(self, context, **response_kwargs):
self.request.current_app = self.request.resolver_match.namespace
return super(DetailView, self).render_to_response(context,
**response_kwargs)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24904>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 3, 2015, 8:51:05 AM6/3/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+--------------------------------------
Reporter: knbk | Owner: knbk
Type: Bug | Status: assigned

Component: Core (URLs) | Version: 1.8
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
-----------------------------+--------------------------------------
Changes (by knbk):

* owner: nobody => knbk
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/24904#comment:1>

Django

unread,
Jun 3, 2015, 10:41:05 AM6/3/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+------------------------------------

Reporter: knbk | Owner: knbk
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 1.8
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 timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24904#comment:2>

Django

unread,
Jun 3, 2015, 1:16:28 PM6/3/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+------------------------------------
Reporter: knbk | Owner: knbk
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by knbk):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/4743

--
Ticket URL: <https://code.djangoproject.com/ticket/24904#comment:3>

Django

unread,
Jun 4, 2015, 8:57:20 PM6/4/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+---------------------------------------------

Reporter: knbk | Owner: knbk
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/24904#comment:4>

Django

unread,
Jun 5, 2015, 11:47:49 AM6/5/15
to django-...@googlegroups.com
#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+---------------------------------------------
Reporter: knbk | Owner: knbk
Type: Bug | Status: closed

Component: Core (URLs) | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f0450c9b1298bf5f39e229aec76c9bf7d57d4479" f0450c9b]:
{{{
#!CommitTicketReference repository=""
revision="f0450c9b1298bf5f39e229aec76c9bf7d57d4479"
Fixed #24904 -- Fixed nested namespaces in current_app.

Fixed reverse() to correctly handled nested namespace lookups
in current_app.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24904#comment:5>

Reply all
Reply to author
Forward
0 new messages