kopia lustrzana https://github.com/wagtail/wagtail
gracefully handle missing model classes in Page.specific()
rodzic
2895aac7f3
commit
eb7dd44055
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue