diff --git a/dlt/sources/helpers/rest_client/paginators.py b/dlt/sources/helpers/rest_client/paginators.py index 82b97e253b..a4290e0b9b 100644 --- a/dlt/sources/helpers/rest_client/paginators.py +++ b/dlt/sources/helpers/rest_client/paginators.py @@ -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.""" diff --git a/tests/sources/helpers/rest_client/test_paginators.py b/tests/sources/helpers/rest_client/test_paginators.py index 49a6275536..85276a263f 100644 --- a/tests/sources/helpers/rest_client/test_paginators.py +++ b/tests/sources/helpers/rest_client/test_paginators.py @@ -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"