Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#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)

14259-testcase.diff (1.2 KB ) - added by Mark Lavin 14 years ago.
Add testcase patch to verify reported behavior

Download all attachments as: .zip

Change History (4)

by Mark Lavin, 14 years ago

Attachment: 14259-testcase.diff added

Add testcase patch to verify reported behavior

comment:1 by Mark Lavin, 14 years ago

Triage Stage: UnreviewedAccepted

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 Chris Beaven, 14 years ago

Resolution: wontfix
Status: newclosed

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.

comment:3 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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