From eb7dd440556778f422a2ceb4dca7275c221d3f1c Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 27 Feb 2015 16:09:12 +0000 Subject: [PATCH] gracefully handle missing model classes in Page.specific() --- wagtail/wagtailcore/models.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index 7346e3b9b..322aa4695 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -425,7 +425,15 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed # the ContentType.objects manager keeps a cache, so this should potentially # avoid a database lookup over doing self.content_type. I think. content_type = ContentType.objects.get_for_id(self.content_type_id) - if isinstance(self, content_type.model_class()): + model_class = content_type.model_class() + if model_class is None: + # Cannot locate a model class for this content type. This might happen + # if the codebase and database are out of sync (e.g. the model exists + # on a different git branch and we haven't rolled back migrations before + # switching branches); if so, the best we can do is return the page + # unchanged. + return self + elif isinstance(self, model_class): # self is already the an instance of the most specific class return self else: