ic-labs / django-icekit

GLAMkit is a next-generation Python CMS by the Interaction Consortium, designed especially for the cultural sector.
http://glamkit.com
MIT License
47 stars 11 forks source link

500 error when deleting pages from admin list view #254

Open markfinger opened 7 years ago

markfinger commented 7 years ago

Seems to be related to everyone's old friend, MPTT: https://sentry.ixcsandbox.com/ic/agsa-staging/group/6564/

I'm getting the same errors in my local dev env, which is running latest icekit on develop

If you go into the page's admin detail, you can still delete the page. Deleting from the page admin list will fail though

CantDisableUpdates: You can't disable/delay mptt updates on Page, it's a proxy model. Call the concrete model instead.
  File "django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/utils/decorators.py", line 145, in inner
    return func(*args, **kwargs)
  File "django/contrib/admin/options.py", line 618, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "django/utils/decorators.py", line 110, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "django/contrib/admin/sites.py", line 233, in inner
    return view(request, *args, **kwargs)
  File "django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "django/utils/decorators.py", line 110, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "django/contrib/admin/options.py", line 1592, in changelist_view
    response = self.response_action(request, queryset=cl.get_queryset(request))
  File "django/contrib/admin/options.py", line 1335, in response_action
    response = func(self, request, queryset)
  File "mptt/admin.py", line 79, in delete_selected_tree
    with queryset.model._tree_manager.delay_mptt_updates():
  File "python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "mptt/managers.py", line 353, in delay_mptt_updates
    with self.disable_mptt_updates():
  File "python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "mptt/managers.py", line 287, in disable_mptt_updates
    % self.model.__name__
jmurty commented 7 years ago

@markfinger @cogat I have "fixed" the issue at hand by removing bulk admin actions that are broken or actively harmful for GLAMkit pages (make published, delete selected) and fixing the publish/unpublish bulk actions to be available on the parent admin page.

I don't know if fixing the bulk delete action properly is worth the (probably very high) effort. The fundamental problem is that MPTT does some custom magic on bulk deletes to avoid the tree structure getting trashed, but this magic is incompatible with admin views based on proxy models like our Pages admin. The only fix I can think of is to do a stupid-simple delete, then trigger something to try and repair any damage done to the MPTT data.