Opened 10 years ago

Last modified 5 years ago

#14761 assigned New feature

URL resolving / reversing design doesn't allow alternate specs

Reported by: samuel337 Owned by: Marten Kenbeek
Component: Core (URLs) Version: master
Severity: Normal Keywords: url resolve reverse
Cc: marten.knbk@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django's URL resolution system is currently based on regexps and is represented by the RegexURLPattern class. There are cases where it would be preferable to subclass this and allow alternate ways of specifying URL patterns that ultimately compile down to regexps.

Right now, this works for URL resolving as during resolution, the resolve method on the RegexURLPattern class is called, and hence subclasses can modify that behaviour. It however, doesn't work for URL reversal, because the resolver class generates the possible matches itself, instead of calling a method on RegexURLPattern or its subclasses as is the case with URL resolution.

The attached patch simply refactors so the resolver calls a method on RegexURLPattern to get possible matches. It passes all the URL tests in Django, is completely backwards-compatible and introduces no new issues or quirks.

I don't believe any new tests are required, and because the new method on RegexURLPattern is marked private (hence subject to change), no new docs are required either. This should stay as an unsupported way to extend Django's URL system until it is fully revamped (support disjunctives, URI templates etc.).

The relevant thread on django-developers is here -

Attachments (1)

ticket-14761.diff (1.4 KB) - added by samuel337 10 years ago.

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by samuel337

Attachment: ticket-14761.diff added

comment:1 Changed 10 years ago by Russell Keith-Magee

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Of course tests are required; you're adding a new piece of functionality. You need to test that the new functionality works, and will continue to work. As it stands, if this patch were applied, a future patch could go back to just calling normalize instead of calling get_possibilities, and the test suite would continue to run, but any custom URLPattern classes would be broken.

comment:2 Changed 9 years ago by anonymous

Severity: Normal
Type: New feature

comment:3 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 7 years ago by Aymeric Augustin

Component: Core (Other)Core (URLs)

comment:6 Changed 5 years ago by Marten Kenbeek

Cc: marten.knbk@… added
Has patch: unset
Needs tests: unset
Owner: changed from nobody to Marten Kenbeek
Patch needs improvement: unset
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top