Opened 16 years ago
Closed 16 years ago
#9139 closed (fixed)
reverse() not finding correct match with some multiple patterns.
Reported by: | 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 , 16 years ago
Component: | Uncategorized → Core framework |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Summary: | NoReverseMatch error should provide more details about urlpattern tried → reverse() not finding correct match with some multiple patterns. |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
This will have been fixed by r9087.
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.)