Opened 8 years ago

Closed 5 years ago

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

Download all attachments as: .zip

Change History (14)

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Avoid duplication naming url pattern to Enforce a check for duplicate named url patterns
  • Triage Stage changed from Unreviewed to Design decision needed

Want to write up a patch to do this check?

Changed 8 years ago by raminf

Checking for duplicate URL names (if specified)

comment:2 Changed 8 years ago by raminf

  • Has patch set

comment:3 Changed 8 years ago by raminf

  • Keywords sprintsept14 added

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

  • Triage Stage changed from Design decision needed to Ready for checkin

comment:5 Changed 8 years ago by russellm

  • Triage Stage changed from Ready for checkin to Accepted

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 8 years ago by russellm

  • Patch needs improvement set

comment:7 Changed 8 years ago by heracek

  • Owner changed from nobody to heracek

Changed 5 years ago by drdee

New patch to check for duplicate urlnames

comment:8 Changed 5 years ago by drdee

  • milestone set to 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 5 years ago by drdee

  • Cc dvanliere@… added

comment:10 Changed 5 years ago by heracek

  • Owner changed from heracek to nobody

comment:11 Changed 5 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:12 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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