Opened 5 years ago

Last modified 3 months ago

#14761 assigned New feature

URL resolving / reversing design doesn't allow alternate specs

Reported by: samuel337 Owned by: knbk
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

Description

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 urlresolvers.py 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 - http://groups.google.com/group/django-developers/browse_thread/thread/c94b551ebd57fbe6/65d79a336fef04b2

Attachments (1)

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

Download all attachments as: .zip

Change History (7)

Changed 5 years ago by samuel337

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by anonymous

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Component changed from Core (Other) to Core (URLs)

comment:6 Changed 3 months ago by knbk

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