# Buggy code
def _extract_sorting(self, limit):
    # Permissions entries are not stored with timestamp, so do not
    # force it.
    result = super()._extract_sorting(limit)
    without_last_modified = [s for s in result if s.field != self.model.modified_field]
    return without_last_modified


# Traceback (IndexError)
ERROR:root:list index out of range
Traceback (most recent call last):
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
response = handler(request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 119, in tm_tween
reraise(*exc_info)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
raise value
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 98, in tm_tween
response = handler(request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/router.py", line 155, in handle_request
view_name
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/view.py", line 612, in _call_view
response = view_callable(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/config/views.py", line 181, in __call__
return view(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 389, in attr_view
return view(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 367, in predicate_wrapper
return view(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 300, in secured_view
return view(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 438, in rendered_view
result = view(context, request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
response = view(request)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/cornice/service.py", line 491, in wrapper
response = view_()
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto/core/resource/__init__.py", line 279, in collection_get
limit, sorting)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto/core/resource/__init__.py", line 1055, in _extract_pagination_rules_from_token
filters = self._build_pagination_rules(sorting, last_record)
File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto/core/resource/__init__.py", line 1021, in _build_pagination_rules
field, direction = sorting[-1]
IndexError: list index out of range

# Fixed code
def _extract_sorting(self, limit):
    # Permissions entries are not stored with timestamp, so do not
    # force it.
    result = super()._extract_sorting(limit)
    without_last_modified = [s for s in result if s.field != self.model.modified_field]
    # For pagination, there must be at least one sort criteria.
    # We use ``uri`` because its values are unique.
    if "uri" not in [s.field for s in without_last_modified]:
        without_last_modified.append(Sort("uri", -1))
    return without_last_modified