diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 2555d0840..50af70493 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -632,9 +632,9 @@ class CursorPagination(BasePagination): else: kwargs = {order_attr + '__gt': current_position} - # If some records contain a null for the ordering field, don't lose them. filter_query = Q(**kwargs) - if reverse: + # If some records contain a null for the ordering field, don't lose them. + if (reverse and not is_reversed) or is_reversed: filter_query |= Q(**{order_attr + '__isnull': True}) queryset = queryset.filter(filter_query) diff --git a/tests/test_pagination.py b/tests/test_pagination.py index fbe064b35..b7633537e 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -1154,7 +1154,7 @@ class TestCursorPaginationWithNulls(TestCase): assert current == [None] assert next == [None] - def test_decending(self): + def test_descending(self): """Test paginating one row at a time, current should go 4, 3, 2, 1, 2, 3, 4.""" self.pagination.ordering = ('-created',) (previous, current, next, previous_url, next_url) = self.get_pages('/')