#14259 closed (wontfix)
URL dispatcher does not reject duplicate URL names
Reported by: | Tobias McNulty | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.2 |
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
It's possible to construct a urls.py with duplicate URL names, and Django just returns the last URL registered with that name when doing reverse(). Django should probably raise an exception so you know that there's an issue with your urls.py and/or an incompatibility between apps.
e.g., when you add this to your urls.py file:
urlpatterns = patterns('views', url(r'^1/$', 'view', name='myname'), url(r'^2/$', 'view', name='myname'), )
reverse() returns /2/ and not /1/.
Attachments (1)
Change History (4)
by , 14 years ago
Attachment: | 14259-testcase.diff added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Added a test case which shows the reported problem. There is a use case for urls will the same name but different arguments that should resolve correctly. Not clear to me what the solution should be (failing hard, resolving to the first or something else) but this looks like a problem.
comment:2 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Having duplicate url names is fine in cases where you use different arguments (and it resolves them correctly based on the arguments passed).
For the case where a named argument is overriding an existing name (with exactly the same arguments), this is a case already documented to "not do":
When you name your URL patterns, make sure you use names that are unlikely to clash with any other application's choice of names. If you call your URL pattern comment, and another application does the same thing, there's no guarantee which URL will be inserted into your template when you use this name.
Add testcase patch to verify reported behavior