Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sentry/api/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ def __init__(self, data_fn):
def get_result(self, limit, cursor=None):
assert limit > 0
offset = cursor.offset if cursor is not None else 0
if offset < 0:
raise BadPaginationError("Pagination offset cannot be negative")

# Request 1 more than limit so we can tell if there is another page
data = self.data_fn(offset=offset, limit=limit + 1)

Expand Down
5 changes: 5 additions & 0 deletions tests/sentry/api/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ def test_invalid_cursor(self) -> None:
response = self.view(request)
assert response.status_code == 400

def test_negative_cursor(self) -> None:
request = self.make_request(GET={"cursor": "0:-1:0"})
response = self.view(request)
assert response.status_code == 400

def test_non_int_per_page(self) -> None:
request = self.make_request(GET={"per_page": "nope"})
response = self.view(request)
Expand Down
Loading