--
Ticket URL: <https://code.djangoproject.com/ticket/17914>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:1>
* cc: bradley.ayers@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:2>
* version: 1.3 => SVN
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:3>
Comment (by Bradley Ayers <bradley.ayers@…>):
It should be noted that this patch is technically backwards incompatible.
After applying this patch, it's no longer possible to use recursive URL
patterns, e.g. consider a project named 'foo', and it had a {{{urls.py}}}
that contained:
{{{
urlpatterns = patterns('', (r'^abc/', include('foo.urls'))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:4>
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Accepting.
Like we talked about on IRC, let's just avoid circular imports when doing
your traversal rather than dropping that functionality.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:5>
Comment (by Bradley Ayers <bradley.ayers@…>):
I've updated the patch to maintain support for recursive urlconfs.
https://github.com/django/django/pull/174
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:6>
Comment (by mtredinnick):
Doing a quick scan of URL reversing during a sprint, the last git code
looks reasonable. Not ready to commit yet -- I haven't fully digested it,
but my intuition is that it's the right kind of thing.
Except(!) that using function objects in reverse() situations is kind of a
"don't do that" kind of situation. We permitted it initially for smooth
integration, but it's kind of a lucky happenstance. My point being, that a
patch of this size is a reasonable to fix this ticket. If it grows to
twice this size, we should maybe just add a "don't do that" note to the
documentation -- the extra complexity isn't worth it.
For now, charge ahead!
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:7>
* cc: amirouche.boubekki@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:8>
* cc: gwahl@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:9>
Comment (by bpeschier):
Closed #21899 as a duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:10>
Comment (by Tonnzor):
Any news here?
Since reverse now accepts app_name -- as well as include -- we could
easily find corresponding namespace. E.g.:
{{{
from django.conf.urls import *
urlpatterns = patterns('',
url(r'^payment/', include('payment.urls', namespace='payment',
app_name='payment')),
)
reverse(view, current_app='payment') # try with current_app given
}}}
As alternative solution -- we could require passing namespace when using
with function. The we could convert function to its name, add
namespace+":" and use existing machinery.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:11>
Comment (by mrmachine):
#21899 was closed a duplicate of this ticket, but I'm not sure they are
the same thing. Will fixing this ticket also fix #21899? This ticket seems
to be about reversing raw callable view functions, for which we have no
way to specify a namespace. The other ticket was about reversing a dotted
path reference to a view function, specified as a string with a namespace.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:12>
* cc: apollo13 (added)
Comment:
Can someone present a usecase for using function references in reverse?
IMO this should just get closed as wontfix and names should be used
throughout instead.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:13>
Comment (by bpeschier):
This feels like using args and kwargs on reverses. Using either function
reverses or namespaces is fine, just don't mix them.
Maybe we should enforce it a bit more like we do with reversing with args
and kwargs?
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:14>
Comment (by guettli):
Replying to [comment:13 apollo13]:
> Can someone present a usecase for using function references in reverse?
IMO this should just get closed as wontfix and names should be used
throughout instead.
For me the view-name is redundant. We try to avoid it. Reversing by
function reference works fine (except this bug). Jumping through the code
with an IDE is much more fun if you use function references.
It would be nice if this could be solved. For our team this means: don't
use namespaced URLs :-(
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:15>
Comment (by apollo13):
Replying to [comment:15 guettli]:
> For me the view-name is redundant. We try to avoid it. Reversing by
function reference works fine (except this bug). Jumping through the code
with an IDE is much more fun if you use function references.
If I remember correctly we've been over the redundancy point on the ML
already, you can always just write your own url function which sets the
path of the function as name, not really redundant imo. Also reversing by
function reference is something which is ugly in templates etc imo… And
redundant is relative anyways, "app:view_name" is imo way nicer than
"app.views.view_name" -- especially if you have nested imports.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:16>
Comment (by timgraham):
I'm in favor of a "won't fix" of this issue and promoting reversing by URL
name as Florian suggested. We could deprecate passing callables to
reverse, but this will probably just needlessly annoy people who are happy
with it. Instead, we could just remove it from the docs like we did with
the `@permalink` decorator.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:17>
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:18>
* Attachment "17914.diff" added.
* needs_better_patch: 1 => 0
Comment:
Added a documentation patch to discourage reversing by callable view.
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:19>
Comment (by apollo13):
LGTM
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:20>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a6acfc31837fd7a9e0e387320d995b2c85cfcfce" a6acfc31]:
{{{
#!CommitTicketReference repository=""
revision="a6acfc31837fd7a9e0e387320d995b2c85cfcfce"
Refs #17914 -- Discouraged using reverese() with callables.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:21>
Comment (by Tim Graham <timograham@…>):
In [changeset:"f32bb3adf039b72cea34347022626231d187e303" f32bb3a]:
{{{
#!CommitTicketReference repository=""
revision="f32bb3adf039b72cea34347022626231d187e303"
[1.8.x] Refs #17914 -- Discouraged using reverese() with callables.
Backport of a6acfc31837fd7a9e0e387320d995b2c85cfcfce from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:22>
* status: new => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/17914#comment:23>