Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination issue in JSONResponseCursorPaginator with empty string cursor value #2016

Merged
merged 1 commit into from
Nov 4, 2024
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
2 changes: 1 addition & 1 deletion dlt/sources/helpers/rest_client/paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def __init__(
def update_state(self, response: Response, data: Optional[List[Any]] = None) -> None:
"""Extracts the cursor value from the JSON response."""
values = jsonpath.find_values(self.cursor_path, response.json())
self._next_reference = values[0] if values else None
self._next_reference = values[0] if values and values[0] else None

def update_request(self, request: Request) -> None:
"""Updates the request with the cursor query parameter."""
Expand Down
6 changes: 6 additions & 0 deletions tests/sources/helpers/rest_client/test_paginators.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ def test_update_state(self):
assert paginator._next_reference == "cursor-2"
assert paginator.has_next_page is True

def test_update_state_when_cursor_path_is_empty_string(self):
paginator = JSONResponseCursorPaginator(cursor_path="next_cursor")
response = Mock(Response, json=lambda: {"next_cursor": "", "results": []})
paginator.update_state(response)
assert paginator.has_next_page is False

def test_update_request(self):
paginator = JSONResponseCursorPaginator(cursor_path="next_cursor")
paginator._next_reference = "cursor-2"
Expand Down
Loading