Opened 9 years ago

Closed 6 years ago

Last modified 5 years ago

#4824 closed (wontfix)

Enforce a check for duplicate named url patterns

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

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 9 years ago.
Checking for duplicate URL names (if specified)
duplicate_urlnames.diff (1.7 KB) - added by drdee 6 years ago.
New patch to check for duplicate urlnames

Download all attachments as: .zip

Change History (14)

comment:1 Changed 9 years ago by Simon G. <dev@…>

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?

Changed 9 years ago by raminf

Attachment: defaults.diff added

Checking for duplicate URL names (if specified)

comment:2 Changed 9 years ago by raminf

Has patch: set

comment:3 Changed 9 years ago by raminf

Keywords: sprintsept14 added

comment:4 Changed 9 years ago by Simon G. <dev@…>

Triage Stage: Design decision neededReady for checkin

comment:5 Changed 9 years ago by Russell Keith-Magee

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 Changed 9 years ago by Russell Keith-Magee

Patch needs improvement: set

comment:7 Changed 9 years ago by Tomáš Horáček

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

Changed 6 years ago by drdee

Attachment: duplicate_urlnames.diff added

New patch to check for duplicate urlnames

comment:8 Changed 6 years ago by drdee

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 Changed 6 years ago by drdee

Cc: dvanliere@… added

comment:10 Changed 6 years ago by Tomáš Horáček

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

comment:11 Changed 6 years ago by Chris Beaven

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 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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