Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#22384 closed Cleanup/optimization (fixed)

Deprecate the ability to reverse by dotted path

Reported by: Tim Graham Owned by: Tim Graham
Component: Core (URLs) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Now that we've deprecated patterns() and recommended actually importing your views module and referencing your view functions (or classes) directly (#22218), I think it's time to deprecate the "Django String Magic" (as Carl termed it) that lets you use strings in url(), e.g. url('^$', 'myapp.views.myview'). As well as reverse by dotted path, e.g. reverse('myapp.views.myview').

Marc mentioned in that ticket "Reversing by dotted path to view is just a bad idea."

Change History (15)

comment:1 by Tim Graham, 11 years ago

I plan to work on this, but will wait to ensure that there are no -1's to the idea, raising it on the mailing list if necessary.

comment:2 by Carl Meyer, 11 years ago

Triage Stage: UnreviewedAccepted

+1 from me.

comment:3 by Aymeric Augustin, 11 years ago

2.0 is a pretty good target for the final removal of this feature.

comment:4 by Gwildor Sok, 11 years ago

I agree that reversing by dotted-path-to-view is "a bad idea". I would even say it's just ridiculous, and I didn't even knew it existed. Obviously you should just use the url name. What would actually happen when you have two urls to the same view? Anyway, I'm all for deprecating that feature.

On the other hand, I'm not entirely convinced about deprecating the dotted-path-to-view in url feature. There are a lot of settings and other things in Django which work that way, and it's a nice feature which prevents the imports from cluttering for the people who are still pro FBV's. Unless it opens up the possibility of removing the necessity of calling as_view() on every CBV in the urls. If deprecating this feature is part of a bigger plan to migrate to cleaner urls for CBV's, then I'm all for it.

comment:5 by Kevin Christopher Henry, 11 years ago

+1 from me. Are there any use cases where someone needs the string version in urls.py to avoid a circular imports problem? Not that I can think of, but I thought I'd mention it...

comment:6 by FunkyBob, 11 years ago

Gwildor, the feature pre-dates named url patterns [yes, there wasn't always that feature].

Also, as I'm sure Alex will point out, it can make debugging harder, as the error of a wrong import won't always show up, and will appear to come from the wrong place when it does fire off.

This will have no impact on needing to call as_view on CBV. The as_view method is a view function factory -- it is what makes the actual view function used to invoke the CBV... you can't do without it.

comment:7 by Tim Graham, 11 years ago

Has patch: set
Summary: Deprecate Django string magic in URLs and the ability to reverse by dotted pathDeprecate the ability to reverse by dotted path

I've reduced the scope of this ticket to only deprecating the ability to reverse by dotted path (instead of also removing the "string magic" in url()). I'll save that bit for a future ticket.

Pull request is up for review.

comment:8 by Simon Charette, 11 years ago

Triage Stage: AcceptedReady for checkin

I left some comments on the PR. Except the doc issue it looks RFC.

comment:9 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 4445d36d471aae81086ed785536687a92e5aaa6d:

Fixed #22384 -- Deprecated reversing URLs by dotted path.

comment:10 by Tim Graham <timograham@…>, 11 years ago

In 250e2b422b4da93f38cd61319b9b3c9f422e6ede:

Silenced some GIS deprecation warnings; refs #22384.

comment:11 by Loic Bistuer <loic.bistuer@…>, 10 years ago

In 45840927d3516770be2654422e752357d5c063a5:

Silenced some deprecation warnings in contrib.sitemaps; refs #22384.

comment:12 by Tim Graham <timograham@…>, 9 years ago

In 785cc71:

Refs #22384 -- Removed the ability to reverse URLs by dotted path per deprecation timeline.

comment:13 by Tim Graham <timograham@…>, 9 years ago

In 6348db37:

Refs #22384 -- Removed obsolete code for the removal of reversing by dotted path.

comment:14 by Tim Graham <timograham@…>, 9 years ago

In 4e400dc:

Refs #22384 -- Readded RegexURLResolver.reverse().

It was removed in 785cc71d5b3300e2702b0b2fc7316e58ca70b563 only because
it was untested and unused in Django itself, however, some third-party
apps use it.

comment:15 by Tim Graham <timograham@…>, 9 years ago

In 8c25d8fc:

[1.10.x] Refs #22384 -- Readded RegexURLResolver.reverse().

It was removed in 785cc71d5b3300e2702b0b2fc7316e58ca70b563 only because
it was untested and unused in Django itself, however, some third-party
apps use it.

Backport of 4e400dcb79bc468ee1ff899312a00ed8dc3e795c from master

Note: See TracTickets for help on using tickets.
Back to Top