Opened 12 months ago

Last modified 3 months ago

#28766 assigned New feature

Add route information to ResolverMatch

Reported by: Benjamin Wohlwend Owned by: Melvyn Sopacua
Component: Core (URLs) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no 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 (10)

comment:1 Changed 12 months ago by Benjamin Wohlwend

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

comment:2 Changed 12 months ago by Tomer Chachamu

Triage Stage: UnreviewedAccepted

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

comment:3 Changed 12 months ago by 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().

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

comment:4 in reply to:  3 Changed 12 months ago by Benjamin Wohlwend

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 Changed 12 months ago by Tim Graham

Yes, that's what I meant to suggest.

comment:6 Changed 12 months ago by Benjamin Wohlwend

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 Changed 12 months ago by Tim Graham

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

comment:8 Changed 12 months ago by Tim Graham

Patch needs improvement: set

comment:9 Changed 3 months ago by Melvyn Sopacua

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 Changed 3 months ago by Tim Graham

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

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