Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#13922 closed (fixed)

Enhanced URL Resolver Match

Reported by: Nowell Strite Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When Django 1.1 was released URLs gained the ability to be nested with
namespaces by adding "app_name" and "namespace" attributes to the
include(...) functions within The reverse(...) function was
updated to allow you to specify namespace and current_app when
resolving URLs, however, we never brought the resolve(...) function up
to speed to include the relevant namespace and app_name data of the
resolved URL. I have taken an initial stab with code and tests (minus
documentation, until this feature is completed and agreed upon by the

In order to achieve this I have graduated the result of the
resolve(...) method to be a ResolverMatch class as opposed to the old
tuple(func, args, kwargs). I have also implemented this feature to
provides backwards compatibility for the old "func, args, kwargs =
resolve(...)" so this feature should hopefully be completely backwards
compatible. The new ResolverMatch class provides access to all
attributes of the resolved URL match such as (url_name, app_name,
namespace, func, args, kwargs).

You can review the diff for this proposal on GitHub.

As well as check out the code:

Nowell Strite

Attachments (1)

resolver-match.diff (8.6 KB) - added by Nowell Strite 9 years ago.
Patch against trunk (created from the referenced GitHub branch)

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by Nowell Strite

The discussion for this topic can be viewed on Django-Dev at:

Changed 9 years ago by Nowell Strite

Attachment: resolver-match.diff added

Patch against trunk (created from the referenced GitHub branch)

comment:2 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [13479]) Fixed #13922 -- Updated resolve() to support namespaces. Thanks to Nowell Strite for the report and patch.

comment:3 Changed 8 years ago by Russell Keith-Magee

For future reference, here's the minor changes between the most patch and what got submitted:

  • PEP8: [var] , not [ var ]
  • Passing in [] as a default argument is a no-no (e.g., namespaces=[]). Instead, pass in None and check for the default value. If you use [] as a default variable, you can get some interesting bugs. The default value is only instantiated once, so it's possible to accidentally modify it over time, and as a result the 'default' value for the function can change.
  • A light cleanup of the docs.
    • Fully documenting the ResolverMatch class
    • Rephrasing the 'versionchanged' notice.
  • Added some extra test cases to catch the unnamed arguments cases. What caught my eye was that all the test cases were expecting tuple() as the value for args.
  • Added some documentation annotating the tests that are being run.
  • Dropped the 'reverse()' method of ResolverMatch. It wasn't tested, and it doesn't make much sense to me for a return value to need a method to return the original input.
  • For the sake of being explicit, I've added tests that match can be assigned to a triple. This is implied by the 'legacy' tests, but better to be explicit with a common use case.

comment:4 Changed 7 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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