# Buggy code
def _obj_capability_dict(self, obj):
    """
    Returns the user_capabilities dictionary for a single item
    If inside of a list view, it runs the prefetching algorithm for
    the entire current page, saves it into context
    """
    view = self.context.get("view", None)
    parent_obj = None
    if view and hasattr(view, "parent_model") and hasattr(view, "get_parent_object"):
        parent_obj = view.get_parent_object()
    if view and view.request and view.request.user:
        capabilities_cache = {}
        # if serializer has parent, it is ListView, apply page capabilities prefetch
        if (
            self.parent
            and hasattr(self, "capabilities_prefetch")
            and self.capabilities_prefetch
        ):
            qs = self.parent.instance
            if "capability_map" not in self.context:
                if hasattr(self, "polymorphic_base"):
                    model = self.polymorphic_base.Meta.model
                    prefetch_list = self.polymorphic_base.capabilities_prefetch
                else:
                    model = self.Meta.model
                    prefetch_list = self.capabilities_prefetch
                self.context["capability_map"] = prefetch_page_capabilities(
                    model, qs, prefetch_list, view.request.user
                )
            if obj.id in self.context["capability_map"]:
                capabilities_cache = self.context["capability_map"][obj.id]
        return get_user_capabilities(
            view.request.user,
            obj,
            method_list=self.show_capabilities,
            parent_obj=parent_obj,
            capabilities_cache=capabilities_cache,
        )
    else:
        # Contextual information to produce user_capabilities doesn't exist
        return {}


# Traceback (AttributeError)
AttributeError: 'super' object has no attribute 'accessible_pk_qs'
2018-03-13 19:49:42,026 ERROR    django.request Internal Server Error: /api/v2/inventory_sources/
Traceback (most recent call last):
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/lib/python2.7/site-packages/awx/wsgi.py", line 65, in _legacy_get_response
return super(AWXWSGIHandler, self)._legacy_get_response(request)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
return func(*args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/awx/api/generics.py", line 284, in dispatch
return super(APIView, self).dispatch(request, *args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 494, in dispatch
response = self.handle_exception(exc)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 454, in handle_exception
self.raise_uncaught_exception(exc)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/views.py", line 491, in dispatch
response = handler(request, *args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/generics.py", line 201, in get
return self.list(request, *args, **kwargs)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/mixins.py", line 45, in list
return self.get_paginated_response(serializer.data)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/serializers.py", line 742, in data
ret = super(ListSerializer, self).data
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/serializers.py", line 262, in data
self._data = self.to_representation(self.instance)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/serializers.py", line 660, in to_representation
self.child.to_representation(item) for item in iterable
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 2070, in to_representation
ret = super(InventorySourceSerializer, self).to_representation(obj)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 683, in to_representation
return super(UnifiedJobTemplateSerializer, self).to_representation(obj)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/serializers.py", line 504, in to_representation
ret[field.field_name] = field.to_representation(attribute)
File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/rest_framework/fields.py", line 1816, in to_representation
return method(value)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 346, in _get_summary_fields
return {} if obj is None else self.get_summary_fields(obj)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 2038, in get_summary_fields
summary_fields = super(InventorySourceSerializer, self).get_summary_fields(obj)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 1973, in get_summary_fields
summary_fields = super(InventorySourceOptionsSerializer, self).get_summary_fields(obj)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 407, in get_summary_fields
user_capabilities = self._obj_capability_dict(obj)
File "/usr/lib/python2.7/site-packages/awx/api/serializers.py", line 436, in _obj_capability_dict
model, qs, prefetch_list, view.request.user
File "/usr/lib/python2.7/site-packages/awx/main/utils/common.py", line 571, in prefetch_page_capabilities
filter_args.append(Q(**{'pk__in': model.accessible_pk_qs(user, '%s_role' % role_type)}))
File "/usr/lib/python2.7/site-packages/awx/main/models/unified_jobs.py", line 199, in accessible_pk_qs
return super(UnifiedJobTemplate, cls).accessible_pk_qs(accessor, role_field)
AttributeError: 'super' object has no attribute 'accessible_pk_qs'

# Fixed code
def _obj_capability_dict(self, obj):
    """
    Returns the user_capabilities dictionary for a single item
    If inside of a list view, it runs the prefetching algorithm for
    the entire current page, saves it into context
    """
    view = self.context.get("view", None)
    parent_obj = None
    if view and hasattr(view, "parent_model") and hasattr(view, "get_parent_object"):
        parent_obj = view.get_parent_object()
    if view and view.request and view.request.user:
        capabilities_cache = {}
        # if serializer has parent, it is ListView, apply page capabilities prefetch
        if (
            self.parent
            and hasattr(self, "capabilities_prefetch")
            and self.capabilities_prefetch
        ):
            qs = self.parent.instance
            if "capability_map" not in self.context:
                if hasattr(self, "polymorphic_base"):
                    model = self.polymorphic_base.Meta.model
                    prefetch_list = self.polymorphic_base._capabilities_prefetch
                else:
                    model = self.Meta.model
                    prefetch_list = self.capabilities_prefetch
                self.context["capability_map"] = prefetch_page_capabilities(
                    model, qs, prefetch_list, view.request.user
                )
            if obj.id in self.context["capability_map"]:
                capabilities_cache = self.context["capability_map"][obj.id]
        return get_user_capabilities(
            view.request.user,
            obj,
            method_list=self.show_capabilities,
            parent_obj=parent_obj,
            capabilities_cache=capabilities_cache,
        )
    else:
        # Contextual information to produce user_capabilities doesn't exist
        return {}