Repository: learningequality/kolibri

Issue:
While searching topic in channel list, it shows error.
## Summary
When learner search for a topic in search option, it gives error.
My server contains channel 8fc515793aad4e52b490b03c48ad21de (Maharashtra State English Medium). 
Note: It is not channel specific.It is coming across the channels.

## System information

 - Version: Kolibri 0.4.5
 - Operating system: Ubuntu 14.04
 - Browser: Chrome


## How to reproduce

1. Login with learner.
2. Search for a topic in search button besides the channel list.

## Screenshots
![2](https://user-images.githubusercontent.com/12776071/31003738-d4a27c38-a50e-11e7-8cab-647a4b4788d0.png)

![1](https://user-images.githubusercontent.com/12776071/31003747-dcf0acac-a50e-11e7-87d7-eb819e22eef5.png)


Discussion:

Resolving patch:
diff --git a/kolibri/content/api.py b/kolibri/content/api.py
--- a/kolibri/content/api.py
+++ b/kolibri/content/api.py
@@ -10,6 +10,7 @@
 from le_utils.constants import content_kinds
 from rest_framework import filters, pagination, viewsets
 from rest_framework.decorators import detail_route
+from rest_framework.generics import get_object_or_404
 from rest_framework.response import Response
 
 from .utils.search import fuzz
@@ -183,8 +184,44 @@ class ContentNodeViewset(viewsets.ModelViewSet):
     filter_class = ContentNodeFilter
     pagination_class = OptionalPageNumberPagination
 
-    def get_queryset(self):
-        return models.ContentNode.objects.all()
+    def prefetch_related(self, queryset):
+        return queryset.prefetch_related(
+            'assessmentmetadata',
+            'files',
+        ).select_related('license')
+
+    def get_queryset(self, prefetch=True):
+        queryset = models.ContentNode.objects.all()
+        if prefetch:
+            return self.prefetch_related(queryset)
+        return queryset
+
+    def get_object(self, prefetch=True):
+        """
+        Returns the object the view is displaying.
+        You may want to override this if you need to provide non-standard
+        queryset lookups.  Eg if objects are referenced using multiple
+        keyword arguments in the url conf.
+        """
+        queryset = self.filter_queryset(self.get_queryset(prefetch=prefetch))
+
+        # Perform the lookup filtering.
+        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
+
+        assert lookup_url_kwarg in self.kwargs, (
+            'Expected view %s to be called with a URL keyword argument '
+            'named "%s". Fix your URL conf, or set the `.lookup_field` '
+            'attribute on the view correctly.' %
+            (self.__class__.__name__, lookup_url_kwarg)
+        )
+
+        filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
+        obj = get_object_or_404(queryset, **filter_kwargs)
+
+        # May raise a permission denied
+        self.check_object_permissions(self.request, obj)
+
+        return obj
 
     @detail_route(methods=['get'])
     def descendants(self, request, **kwargs):
diff --git a/kolibri/content/serializers.py b/kolibri/content/serializers.py
--- a/kolibri/content/serializers.py
+++ b/kolibri/content/serializers.py
@@ -82,11 +82,6 @@ def to_representation(self, data):
         # so, first get a queryset from the Manager if needed
         data = data.all() if isinstance(data, Manager) else data
 
-        data = data.prefetch_related(
-            'assessmentmetadata',
-            'files',
-        ).select_related('license')
-
         cache_key = None
         # Cache parent look ups only
         if "parent" in self.context['request'].GET:


Test patch: