Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Remove related objects for these users" (admin interface action) fails with 500 error #2148

Closed
jnm opened this issue Jan 2, 2019 · 1 comment
Assignees
Labels
bug Things broken and not working as expected

Comments

@jnm
Copy link
Member

jnm commented Jan 2, 2019

This custom Django admin interface action allows us to delete user accounts by:

  1. Removing all their related KPI objects (from KPI's admin interface);
  2. Removing all their related KC objects and their account itself (from KC's admin interface).

This must be fixed to complete https://github.com/kobotoolbox/tasks/issues/32.

django-guardian (within KPI) is choking on the KoBoCAT permissions: https://sentry.kbtdev.org/kobo/kpi-backend/issues/18761/

AttributeError: 'NoneType' object has no attribute '_base_manager'
  File "django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_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 1576, 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 "hub/actions.py", line 57, in delete_related_objects
    modeladmin.admin_site, using
  File "django/contrib/admin/utils.py", line 153, in get_deleted_objects
    to_delete = collector.nested(format_callback)
  File "django/contrib/admin/utils.py", line 213, in nested
    roots.extend(self._nested(root, seen, format_callback))
  File "django/contrib/admin/utils.py", line 198, in _nested
    ret = [format_callback(obj)]
  File "django/contrib/admin/utils.py", line 126, in format_callback
    force_text(obj))
  File "django/utils/encoding.py", line 92, in force_text
    s = six.text_type(s)
  File "guardian/models.py", line 35, in __unicode__
    unicode(self.content_object),
  File "django/contrib/contenttypes/fields.py", line 235, in __get__
    rel_obj = ct.get_object_for_this_type(pk=getattr(instance, self.fk_field))
  File "django/contrib/contenttypes/models.py", line 196, in get_object_for_this_type
    return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
@jnm jnm self-assigned this Jan 2, 2019
@jnm jnm added the bug Things broken and not working as expected label Jan 2, 2019
@jnm
Copy link
Member Author

jnm commented Jan 2, 2019

lolll thanks past self:

# Do NOT try to `print` or do anything else that would `repr()` this
# queryset, or you'll be greeted by
# `AttributeError: 'NoneType' object has no attribute '_base_manager'`

noliveleger added a commit that referenced this issue Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things broken and not working as expected
Projects
None yet
Development

No branches or pull requests

1 participant