#11191: Admin throws 500 instead of 404 error when passing a string as the PK
argument for a model with an integer PK field.
-------------------------------------------+--------------------------------
Reporter: mrmachine | Owner: nobody
Status: new | Milestone: 1.1
Component: django.contrib.admin | Version: SVN
Resolution: | Keywords: admin urls pk
integer ValueError
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------------+--------------------------------
Changes (by mrmachine):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I've uploaded a patch with a failing test case.
I suspect that the best place to fix this is in the admin application's
`change_view`. The raw ORM should probably continue to fail with an
exception when a user tries to get an object with a PK of an invalid type,
but this particular (and perhaps other) core admin views which have been
designed to work with multiple models which have integer and string PKs
need to catch this and return a correct response.
Likewise, if users have their own URLs which need to work with multiple
models which have both integer or string PKs, they will need to catch this
in their own code. For cases where the URL is only specifying one type of
PK (integer or string) for one model (or several which all use the same
type of PK), the user can achieve the correct response by changing their
URL pattern to accept only digits or letters in the PK field.
One alternative would be for the `get()` (and related/affected) methods to
always raise !DoesNotExist when a PK of an invalid type is specified. This
would avoid the user having to catch this in their own code, but could
mask other problems and feels like the wrong approach.
--
Ticket URL: <http://code.djangoproject.com/ticket/11191#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---