#4824 closed (wontfix)
Enforce a check for duplicate named url patterns
Reported by: | 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)
Change History (14)
comment:1 by , 17 years ago
Summary: | Avoid duplication naming url pattern → Enforce a check for duplicate named url patterns |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
Has patch: | set |
---|
comment:3 by , 17 years ago
Keywords: | sprintsept14 added |
---|
comment:4 by , 17 years ago
Triage Stage: | Design decision needed → Ready for checkin |
---|
comment:5 by , 17 years ago
Triage Stage: | Ready for checkin → 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 by , 17 years ago
Patch needs improvement: | set |
---|
comment:7 by , 17 years ago
Owner: | changed from | to
---|
by , 14 years ago
Attachment: | duplicate_urlnames.diff added |
---|
New patch to check for duplicate urlnames
comment:8 by , 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 , 14 years ago
Cc: | added |
---|
comment:10 by , 14 years ago
Owner: | changed from | to
---|
comment:11 by , 14 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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.
Want to write up a patch to do this check?