Opened 6 years ago

Closed 5 years ago

#28766 closed New feature (fixed)

Add route information to ResolverMatch

Reported by: Benjamin Wohlwend Owned by: Melvyn Sopacua
Component: Core (URLs) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The new route-based URL patterns are fantastic, but when introspecting the ResolverMatch object, the route information is not available. The route would be of great use for tools/libraries that need to introspect the URL resolver.

GitHub PR with a first try at adding this will follow.

Change History (13)

comment:1 by Benjamin Wohlwend, 6 years ago

Has patch: set
Owner: changed from nobody to Benjamin Wohlwend
Status: newassigned

comment:2 by Tomer Chachamu, 6 years ago

Triage Stage: UnreviewedAccepted

Thanks for the patch. If it's ready to review you can deassign the Trac ticket. :)

comment:3 by Tim Graham, 6 years ago

For URL patterns that use re_path() is the route already available from ResolverMatch? If not, I'm unsure why this attribute would only be set for path().

(By the way, there's no need to deassign the ticket to get it in the review queue.)

in reply to:  3 comment:4 by Benjamin Wohlwend, 6 years ago

Replying to Tim Graham:

For URL patterns that use re_path() is the route already available from ResolverMatch? If not, I'm unsure why this attribute would only be set for path().

re_path() uses RegexPattern, which doesn't have a route, but a regex. Do you think the regex should be set in that case? That would simplify the code a bit. Instead of getattr(pattern._route), we could just use str(pattern) (__str__ prints _route for RoutePattern objects, and _regex for RegexPattern).

comment:5 by Tim Graham, 6 years ago

Yes, that's what I meant to suggest.

comment:6 by Benjamin Wohlwend, 6 years ago

OK. However, in that case I think the attribute on ResolverMatch should be named differently, since AFAICT, "route" is specific to the new simplified URLs from DEP 201. Maybe ResolverMatch.pattern?

comment:7 by Tim Graham, 6 years ago

The first argument of re_path() is also documented as route so I think it's okay to use that.

comment:8 by Tim Graham, 6 years ago

Patch needs improvement: set

comment:9 by Melvyn Sopacua, 6 years ago

Has patch: unset
Owner: changed from Benjamin Wohlwend to Melvyn Sopacua
Patch needs improvement: unset
Version: 2.0master

Working on patch + test + docs.

@tim Do I need to submit a new document for contribution or can you link the one I submitted already to this [github account](https://github.com/mes3yd/)? The old account will get closed as soon as there's nothing pending on it anymore.

comment:10 by Tim Graham, 6 years ago

You don't need to submit another Contributor License Agreement. Those agreements are linked to you, not to your GitHub account.

comment:11 by Tim Graham, 5 years ago

Has patch: set
Patch needs improvement: set

PR with comments for improvement.

comment:12 by Xavier Fernandez, 5 years ago

Patch needs improvement: unset

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

Resolution: fixed
Status: assignedclosed

In 79c196cf:

Fixed #28766 -- Added ResolverMatch.route.

Co-Authored-By: Xavier Fernandez <xavier.fernandez@…>

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