#10223 closed (wontfix)
Admin has a bug for primary keys that contain slashes
Reported by: | HuCy | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ||
Cc: | matthew@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
If your Model's primary key contains slashes,
the "View on Site" button does not work, because the wrong number of arguments are
passed to django.contrib.contenttypes.views.shortcut.
The attached patch fixes this issue by splitting to a maximum number of 3 elements.
Patch done by Christoph Borgolte and Christian Klein
Attachments (4)
Change History (14)
by , 16 years ago
Attachment: | admin-pk.diff added |
---|
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Needs tests: | set |
---|
by , 16 years ago
Attachment: | 10223-test.diff added |
---|
comment:3 by , 16 years ago
comment:4 by , 16 years ago
Needs tests: | unset |
---|
comment:5 by , 16 years ago
Cc: | added |
---|
comment:6 by , 16 years ago
Patch needs improvement: | set |
---|
by , 16 years ago
Attachment: | 10223-charfield_pk_with_slashes_view_on_site-1.0.x.diff added |
---|
Patch from HuCy and tests from mmarshall adapted for the 1.0.x branch as of r10618
comment:7 by , 16 years ago
Patch needs improvement: | unset |
---|
by , 16 years ago
Attachment: | 10223-charfield_pk_with_slashes_view_on_site.diff added |
---|
Patch from HuCy? and tests from mmarshall, modified to actually test things with the legacy AdminSite?.root view
comment:8 by , 16 years ago
Patch needs improvement: | set |
---|
The problem appears to be much deeper than just the link on site. Consider a model with a CharField primary key, and an instance with a key value of foo/bar/whiz, using the include() style of admin URL declaration:
- If you use the admin to add an object with a slash in the primary key, and use the "save and continue editing" button, you get redirected to /admin/app/model/foo/bar/whiz, but if you use save, then use the admin to go back into the object definition, the url is /admin/app/model/foo_2Fbar_2Fwhiz/
- If you are on /admin/app/model/foo/bar/whiz, the breadcrumb links are wrong - they slice the path at the wrong slash.
- If you are on /admin/app/model/foo/bar/whiz, the view on site links to /admin/myapp/charpkmodel/r/28/foo/bar/whiz/, not /admin/r/28/foo/bar/whiz/
- If you are on /admin/app/model/foo_2Fbar_2Fwhiz/, the link on site is to /admin/r/28/foo_2Fbar_2Fwhiz/ - which raises a 404, since there is no object with PK foo_2Fbar_2Fwhiz
I'm guessing there will be other problems.
comment:9 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Since this only happens with the legacy version of admin URLs, I don't see the point in fixing it. If you have this bug, just don't use AdminSite.root
.
The problem only applies to the AdminSite.root, which is deprecated. The new method using include(admin.site.urls) uses an re with .+
I've submitted a test, but it tests against the new method.