Opened 16 years ago

Closed 15 years ago

#9139 closed (fixed)

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

Reported by: samt@… Owned by: Malcolm Tredinnick
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: no UI/UX: no

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?

Change History (2)

comment:1 by Malcolm Tredinnick, 16 years ago

Component: UncategorizedCore framework
Owner: changed from nobody to Malcolm Tredinnick
Status: newassigned
Summary: NoReverseMatch error should provide more details about urlpattern triedreverse() not finding correct match with some multiple patterns.
Triage Stage: UnreviewedAccepted

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 by Malcolm Tredinnick, 15 years ago

Resolution: fixed
Status: assignedclosed

This will have been fixed by r9087.

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