diff --git a/course_discovery/apps/edx_elasticsearch_dsl_extensions/viewsets.py b/course_discovery/apps/edx_elasticsearch_dsl_extensions/viewsets.py index eb5c77fd02..fddfa5e326 100644 --- a/course_discovery/apps/edx_elasticsearch_dsl_extensions/viewsets.py +++ b/course_discovery/apps/edx_elasticsearch_dsl_extensions/viewsets.py @@ -136,20 +136,11 @@ def get_next_link(self): return replace_query_param(url, self.search_after_param, json.dumps(last_item_sort)) def _get_last_item_sort(self): - last_item = self.page.object_list[-1] if self.page.object_list else None - return list(last_item.meta.sort) if last_item else None - - def get_paginated_response(self, data): - """ - Get paginated response, including search_after value for the next page. - """ - response = super().get_paginated_response(data) view = self.request.parser_context.get("view") last_item = getattr(view, "last_item", None) - search_after = last_item.meta.sort.copy() if last_item else None - next_link = response.data.pop("next", None) - response.data["next"] = search_after if next_link else None - return response + last_item = last_item.meta.sort.copy() if last_item else None + setattr(view, "last_item", None) # clearing the last_item attribute to prevent it from being used in the next request + return last_item class BaseElasticsearchDocumentViewSet(mixins.DetailMixin, mixins.FacetMixin, DocumentViewSet):