summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Támara <igor@tamarapatino.org>2013-03-01 00:01:25 -0500
committerRamiro Morales <cramm0@gmail.com>2013-03-06 21:38:44 -0300
commite2ee02c5bd412a6a1b33353cac1a222be989d71f (patch)
tree42bbc120fbcf4429bae534de4486b0fc048c377b
parentc31a9793c62457a68217326e9dfded8f0fb38d96 (diff)
Fixed #19951 -- Admin: Invalid model PK values shouldn't cause 500 status.
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.
-rw-r--r--django/contrib/admin/options.py2
-rw-r--r--tests/admin_views/tests.py15
2 files changed, 13 insertions, 4 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index cce92c6a95..567f7cf990 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -501,7 +501,7 @@ class ModelAdmin(BaseModelAdmin):
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):
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 0bcfc0c034..ff2eb95745 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -124,13 +124,22 @@ class AdminViewBasicTest(TestCase):
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.