Skip to content

Commit 1d9077d

Browse files
authored
Merge pull request #1103 from numberly/fix_empty_paging
This commit provides a fix to the situation when iterating on a ResultSet, the driver aborts the iteration if the server returns an empty page even if there are next pages available. Python driver is affected by the same problem as JAVA-2934 This fix is similar to apache/cassandra-java-driver#1544
1 parent a51ed11 commit 1d9077d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cassandra/cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,6 +5141,7 @@ def next(self):
51415141
if not self.response_future._continuous_paging_session:
51425142
self.fetch_next_page()
51435143
self._page_iter = iter(self._current_rows)
5144+
return self.next()
51445145

51455146
return next(self._page_iter)
51465147

tests/unit/test_resultset.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ def test_iter_paged(self):
4141
type(response_future).has_more_pages = PropertyMock(side_effect=(True, True, False)) # after init to avoid side effects being consumed by init
4242
self.assertListEqual(list(itr), expected)
4343

44+
def test_iter_paged_with_empty_pages(self):
45+
expected = list(range(10))
46+
response_future = Mock(has_more_pages=True, _continuous_paging_session=None)
47+
response_future.result.side_effect = [
48+
ResultSet(Mock(), []),
49+
ResultSet(Mock(), [0, 1, 2, 3, 4]),
50+
ResultSet(Mock(), []),
51+
ResultSet(Mock(), [5, 6, 7, 8, 9]),
52+
]
53+
rs = ResultSet(response_future, [])
54+
itr = iter(rs)
55+
self.assertListEqual(list(itr), expected)
56+
4457
def test_list_non_paged(self):
4558
# list access on RS for backwards-compatibility
4659
expected = list(range(10))

0 commit comments

Comments
 (0)