Opened 17 years ago

Closed 14 years ago

Last modified 13 years ago

#4824 closed (wontfix)

Enforce a check for duplicate named url patterns

Reported by: Favo <favo@…> Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: sprintsept14
Cc: favo@…, dvanliere@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The current naming url pattern don't check the duplication naming. As it said in documentatioin,

Note

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.

Putting a prefix on your URL names, perhaps derived from the application name, will decrease the chances of collision. We recommend something like myapp-comment instead of comment.

I think it's quite easy to check the duplication naming url pattern in the construction stage and should be.

Attachments (2)

defaults.diff (729 bytes ) - added by raminf 17 years ago.
Checking for duplicate URL names (if specified)
duplicate_urlnames.diff (1.7 KB ) - added by drdee 14 years ago.
New patch to check for duplicate urlnames

Download all attachments as: .zip

Change History (14)

comment:1 by Simon G. <dev@…>, 17 years ago

Summary: Avoid duplication naming url patternEnforce a check for duplicate named url patterns
Triage Stage: UnreviewedDesign decision needed

Want to write up a patch to do this check?

by raminf, 17 years ago

Attachment: defaults.diff added

Checking for duplicate URL names (if specified)

comment:2 by raminf, 17 years ago

Has patch: set

comment:3 by raminf, 17 years ago

Keywords: sprintsept14 added

comment:4 by Simon G. <dev@…>, 17 years ago

Triage Stage: Design decision neededReady for checkin

comment:5 by Russell Keith-Magee, 17 years ago

Triage Stage: Ready for checkinAccepted

This is good idea in principle, but the patch doesn't really fix the problem. If you have multiple urls.py files, this approach won't identify duplicates across the files.

On a housekeeping note - Django uses 4 spaces, not tabs, for indentation.

comment:6 by Russell Keith-Magee, 17 years ago

Patch needs improvement: set

comment:7 by Tomáš Horáček, 17 years ago

Owner: changed from nobody to Tomáš Horáček

by drdee, 14 years ago

Attachment: duplicate_urlnames.diff added

New patch to check for duplicate urlnames

comment:8 by drdee, 14 years ago

milestone: 1.3
Patch needs improvement: unset

Hi,

I have taken the liberty to come up with a new patch to check for duplicate urlnames across different apps (but in the same project). This function loads the different urls.py file, constructs a list of urlnames and raises an ImproperlyConfigured error when it finds a duplicate name. The call to this function is missing because I do not think it should be part of patterns() like the previous patch: that would create too many unnecessary calls to the function. IMHO, it's better to put a call to this function around model initialization, but I do not know what would be an appropriate place to do that, so I leave that decision to the senior django developers. I can also imagine that this function needs to move to a different location then the current /django/conf/urls/defaults.py but for the sake of the ticket I have left it in the same place as the previous patch.

Best,

Diederik

comment:9 by drdee, 14 years ago

Cc: dvanliere@… added

comment:10 by Tomáš Horáček, 14 years ago

Owner: changed from Tomáš Horáček to nobody

comment:11 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:12 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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