wagtail: Latest code throws 'unexpected keyword argument parent_page' in django-modelcluster

OK I probably shouldn’t be using the bleeding edge code, but I need some of the 1.4 fixes and features for my project and it was working well before. I’m getting an error with the latest code ever since the commits on Jan 25th to add the new permissions policy. Every time I try to create a new page I get:

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'

The old code used to call validate_page_form(form, parent_page) but this has been deleted and replaced by form = form_class(request.POST, request.FILES, instance=page, parent_page=parent_page) along with the offending parent_page.

This looks like an accidental bug (possibly triggered by my page models?) but I don’t understand this part of the code well enough to know how to fix it. Any help appreciated, even if it’s “don’t use the latest code yet”.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Funny that we all encounter the same problem within minutes. I have the same problem.

I have a working fix, though:

from wagtail.wagtailadmin.forms import WagtailAdminPageForm
from wagtail.wagtailadmin.edit_handlers import TabbedInterface as OriginalTabbedInterface

class TabbedInterface(OriginalTabbedInterface):

    def __init__(self, children, base_form_class=WagtailAdminPageForm):
        super().__init__(children, base_form_class)

-> Use this TabbedInterface instead of the shipped one.

@gasman: can you confirm that this is sufficient or do you see any side effects? AFAIK only the base_form_class must be adjusted.

@everyone: does this work for u as well?

@timheap thanks for this. @kaedroho, can you please review, with the aim of getting it in 1.4.2 in the next few days?

I’ve submitted a PR that should fix this issue. When adding a custom EditHandler to a Page class without setting a custom base_form_class for the EditHandler, the base_form_class is now taken from the model instead. This should make all previous custom EditHandlers work again.

I’ve also added a system check to ensure that form classes returned from Page EditHandlers subclass WagtailAdminPageForm, which should warn people when they make a custom EditHandler that would break the Page edit views.

Closing as unable to replicate.