Code

Opened 6 years ago

Closed 6 years ago

#9139 closed (fixed)

reverse() not finding correct match with some multiple patterns.

Reported by: samt@… Owned by: mtredinnick
Component: Core (Other) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If I incorrectly create two urlpatterns to the same function:

urlpatterns = patterns(
  (r'view/$', 'myproject.myapp.view.viewer'),
  (r'view/(.*)/(.*)', 'myproject.myapp.view.viewer'),

and then refer to the second one in the template:

<a href="{%url myproject.myapp.view.viewer 'showitem',12%}">

I get the following error:

NoReverseMatch: Reverse for 'myproject.myapp.view.viewer' with arguments '(u'showitem',12L)' and keyword arguments '{}' not found.

The problem is that this message isn't clear. At the very least, it should include the regex of the urlpattern it tried and failed to reverse to.

I took a stab at fixing this at the point the NoReverseMatch was generated, but the reverse_dict is keyed with functions and get_callable isn't returning the exact same function+address each time, so I can't retrieve urlpattern details at that point.

Maybe an exception should be generated at the time you try to add a second unnamed urlpattern to the same function?

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by mtredinnick

  • Component changed from Uncategorized to Core framework
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to mtredinnick
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Summary changed from NoReverseMatch error should provide more details about urlpattern tried to reverse() not finding correct match with some multiple patterns.
  • Triage Stage changed from Unreviewed to Accepted

Except that the whole point is that it's not an error to have two patterns with the same names. So there's a different bug here: why isn't it matching the second pattern?

The error is actually very clear. It's saying that it couldn't find a match for that name with those parameters. It's not saying "and I only tried the first one" -- you're surmising that's the case because you (wisely, I might add :-) ) believe the function is behaving correctly. Sadly, we're not that smart. :-(

I'll look into this a bit more. Something is going wrong here.

(Changing title to reflect the real problem.)

comment:2 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

This will have been fixed by r9087.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.