Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16917 -- Don't try to use the model name for a ContentType's u…

…nicode representation if the model no longer exists. Thanks Ivan Sagalaev for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16895 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0a9c52e013dede9c765fb2550cdef17caaafdccd 1 parent 4dab2d2
@carljm carljm authored
View
6 django/contrib/contenttypes/models.py
@@ -92,11 +92,11 @@ def __unicode__(self):
#
# We return self.name only when users have changed its value from the
# initial verbose_name_raw and might rely on it.
- meta = self.model_class()._meta
- if self.name != meta.verbose_name_raw:
+ model = self.model_class()
+ if not model or self.name != model._meta.verbose_name_raw:
return self.name
else:
- return force_unicode(meta.verbose_name)
+ return force_unicode(model._meta.verbose_name)
def model_class(self):
"Returns the Python model class for this type of content."
View
13 django/contrib/contenttypes/tests.py
@@ -109,3 +109,16 @@ def test_shortcut_view_without_get_absolute_url(self):
obj = FooWithoutUrl.objects.create(name="john")
self.assertRaises(Http404, shortcut, request, user_ct.id, obj.id)
+
+ def test_missing_model(self):
+ """
+ Ensures that displaying content types in admin (or anywhere) doesn't
+ break on leftover content type records in the DB for which no model
+ is defined anymore.
+ """
+ ct = ContentType.objects.create(
+ name = 'Old model',
+ app_label = 'contenttypes',
+ model = 'OldModel',
+ )
+ self.assertEqual(unicode(ct), u'Old model')
Please sign in to comment.
Something went wrong with that request. Please try again.