Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#14259 closed (wontfix)

URL dispatcher does not reject duplicate URL names

Reported by: tobias 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: UI/UX:


It's possible to construct a 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 and/or an incompatibility between apps.

e.g., when you add this to your 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 mlavin 6 years ago.
Add testcase patch to verify reported behavior

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by mlavin

Add testcase patch to verify reported behavior

comment:1 Changed 6 years ago by mlavin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to 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 Changed 6 years ago by SmileyChris

  • Resolution set to wontfix
  • Status changed from new to 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.

comment:3 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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