Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19951 -- Admin: Invalid model PK values shouldn't cause 500 st…

…atus.

Avoid ValueError in admin when passing a string as PK for an inherited
model with an integer PK field.

Thanks ikks for the patch. See also #11191.
  • Loading branch information...
commit e2ee02c5bd412a6a1b33353cac1a222be989d71f 1 parent c31a979
@ikks ikks authored ramiro committed
Showing with 13 additions and 4 deletions.
  1. +1 −1  django/contrib/admin/options.py
  2. +12 −3 tests/admin_views/tests.py
View
2  django/contrib/admin/options.py
@@ -501,7 +501,7 @@ def get_object(self, request, object_id):
try:
object_id = model._meta.pk.to_python(object_id)
return queryset.get(pk=object_id)
- except (model.DoesNotExist, ValidationError):
+ except (model.DoesNotExist, ValidationError, ValueError):
return None
def get_changelist_form(self, request, **kwargs):
View
15 tests/admin_views/tests.py
@@ -124,13 +124,22 @@ def testBasicEditGet(self):
def testBasicEditGetStringPK(self):
"""
- A smoke test to ensure GET on the change_view works (returns an HTTP
- 404 error, see #11191) when passing a string as the PK argument for a
- model with an integer PK field.
+ Ensure GET on the change_view works (returns an HTTP 404 error, see
+ #11191) when passing a string as the PK argument for a model with an
+ integer PK field.
"""
response = self.client.get('/test_admin/%s/admin_views/section/abc/' % self.urlbit)
self.assertEqual(response.status_code, 404)
+ def testBasicInheritanceGetStringPK(self):
+ """
+ Ensure GET on the change_view works on inherited models (returns an
+ HTTP 404 error, see #19951) when passing a string as the PK argument
+ for a model with an integer PK field.
+ """
+ response = self.client.get('/test_admin/%s/admin_views/supervillain/abc/' % self.urlbit)
+ self.assertEqual(response.status_code, 404)
+
def testBasicAddPost(self):
"""
A smoke test to ensure POST on add_view works.
Please sign in to comment.
Something went wrong with that request. Please try again.