# Buggy code
def check(cls, **kwargs):
    errors = super(Page, cls).check(**kwargs)

    # Check that foreign keys from pages are not configured to cascade
    # This is the default Django behaviour which must be explicitly overridden
    # to prevent pages disappearing unexpectedly and the tree being corrupted

    # get names of foreign keys pointing to parent classes (such as page_ptr)
    field_exceptions = [
        field.name
        for model in [cls] + list(cls._meta.get_parent_list())
        for field in model._meta.parents.values()
        if field
    ]

    for field in cls._meta.fields:
        if isinstance(field, models.ForeignKey) and field.name not in field_exceptions:
            if field.rel.on_delete == models.CASCADE:
                errors.append(
                    checks.Warning(
                        "Field hasn't specified on_delete action",
                        hint="Set on_delete=models.SET_NULL and make sure the field is nullable.",
                        obj=field,
                        id="wagtailcore.W001",
                    )
                )

    if not isinstance(cls.objects, PageManager):
        errors.append(
            checks.Error(
                "Manager does not inherit from PageManager",
                hint="Ensure that custom Page managers inherit from {}.{}".format(
                    PageManager.__module__, PageManager.__name__
                ),
                obj=cls,
                id="wagtailcore.E002",
            )
        )

    try:
        cls.clean_subpage_models()
    except (ValueError, LookupError) as e:
        errors.append(
            checks.Error(
                "Invalid subpage_types setting for %s" % cls,
                hint=str(e),
                id="wagtailcore.E002",
            )
        )

    try:
        cls.clean_parent_page_models()
    except (ValueError, LookupError) as e:
        errors.append(
            checks.Error(
                "Invalid parent_page_types setting for %s" % cls,
                hint=str(e),
                id="wagtailcore.E002",
            )
        )

    from wagtail.wagtailadmin.forms import WagtailAdminPageForm

    if not issubclass(cls.base_form_class, WagtailAdminPageForm):
        errors.append(
            checks.Error(
                "base_form_class does not extend WagtailAdminPageForm",
                hint="Ensure that {}.{} extends WagtailAdminPageForm".format(
                    cls.base_form_class.__module__, cls.base_form_class.__name__
                ),
                obj=cls,
                id="wagtailcore.E002",
            )
        )
    # Sadly, there is no way of checking the form class returned from
    # cls.get_edit_handler().get_form_class(cls), as these calls can hit
    # the DB in order to fetch content types.

    return errors


# Traceback (TypeError)
Traceback (most recent call last):
File "/Users/matt/Dev/MyProject/MyApp/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/matt/Dev/MyProject/MyApp/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/matt/Dev/MyProject/MyApp/lib/python3.4/site-packages/django/views/decorators/cache.py", line 43, in _cache_controlled
response = viewfunc(request, *args, **kw)
File "/Users/matt/Dev/MyProject/MyApp/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/matt/Dev/MyProject/MyApp/MyApp/wagtail/wagtailadmin/views/pages.py", line 169, in create
parent_page=parent_page)
File "/Users/matt/Dev/MyProject/MyApp/lib/python3.4/site-packages/modelcluster/forms.py", line 208, in __init__
super(ClusterForm, self).__init__(data, files, instance=instance, prefix=prefix, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'parent_page'

# Fixed code
def check(cls, **kwargs):
    errors = super(Page, cls).check(**kwargs)

    # Check that foreign keys from pages are not configured to cascade
    # This is the default Django behaviour which must be explicitly overridden
    # to prevent pages disappearing unexpectedly and the tree being corrupted

    # get names of foreign keys pointing to parent classes (such as page_ptr)
    field_exceptions = [
        field.name
        for model in [cls] + list(cls._meta.get_parent_list())
        for field in model._meta.parents.values()
        if field
    ]

    for field in cls._meta.fields:
        if isinstance(field, models.ForeignKey) and field.name not in field_exceptions:
            if field.rel.on_delete == models.CASCADE:
                errors.append(
                    checks.Warning(
                        "Field hasn't specified on_delete action",
                        hint="Set on_delete=models.SET_NULL and make sure the field is nullable.",
                        obj=field,
                        id="wagtailcore.W001",
                    )
                )

    if not isinstance(cls.objects, PageManager):
        errors.append(
            checks.Error(
                "Manager does not inherit from PageManager",
                hint="Ensure that custom Page managers inherit from {}.{}".format(
                    PageManager.__module__, PageManager.__name__
                ),
                obj=cls,
                id="wagtailcore.E002",
            )
        )

    try:
        cls.clean_subpage_models()
    except (ValueError, LookupError) as e:
        errors.append(
            checks.Error(
                "Invalid subpage_types setting for %s" % cls,
                hint=str(e),
                id="wagtailcore.E002",
            )
        )

    try:
        cls.clean_parent_page_models()
    except (ValueError, LookupError) as e:
        errors.append(
            checks.Error(
                "Invalid parent_page_types setting for %s" % cls,
                hint=str(e),
                id="wagtailcore.E002",
            )
        )

    from wagtail.wagtailadmin.forms import WagtailAdminPageForm

    if not issubclass(cls.base_form_class, WagtailAdminPageForm):
        errors.append(
            checks.Error(
                "{}.base_form_class does not extend WagtailAdminPageForm".format(
                    cls.__name__
                ),
                hint="Ensure that {}.{} extends WagtailAdminPageForm".format(
                    cls.base_form_class.__module__, cls.base_form_class.__name__
                ),
                obj=cls,
                id="wagtailcore.E002",
            )
        )

    edit_handler = cls.get_edit_handler()
    if not issubclass(edit_handler.get_form_class(cls), WagtailAdminPageForm):
        errors.append(
            checks.Error(
                "{cls}.get_edit_handler().get_form_class({cls}) does not extend WagtailAdminPageForm".format(
                    cls=cls.__name__
                ),
                hint="Ensure that the EditHandler for {cls} creates a subclass of WagtailAdminPageForm".format(
                    cls=cls.__name__
                ),
                obj=cls,
                id="wagtailcore.E003",
            )
        )

    return errors