From 229aec8aef953edf23629b91f8f83b4c0f67e9e0 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Mon, 30 Aug 2021 11:24:49 +0200 Subject: [PATCH] ResultSet: handle empty non-final pages on ResultSet iteration 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 https://github.com/datastax/java-driver/pull/1544 --- cassandra/cluster.py | 1 + tests/unit/test_resultset.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 7e101afba8..c2d2e719ac 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -5141,6 +5141,7 @@ def next(self): if not self.response_future._continuous_paging_session: self.fetch_next_page() self._page_iter = iter(self._current_rows) + return self.next() return next(self._page_iter) diff --git a/tests/unit/test_resultset.py b/tests/unit/test_resultset.py index 1af3e849b6..b37c3a2594 100644 --- a/tests/unit/test_resultset.py +++ b/tests/unit/test_resultset.py @@ -41,6 +41,19 @@ def test_iter_paged(self): type(response_future).has_more_pages = PropertyMock(side_effect=(True, True, False)) # after init to avoid side effects being consumed by init self.assertListEqual(list(itr), expected) + def test_iter_paged_with_empty_pages(self): + expected = list(range(10)) + response_future = Mock(has_more_pages=True, _continuous_paging_session=None) + response_future.result.side_effect = [ + ResultSet(Mock(), []), + ResultSet(Mock(), [0, 1, 2, 3, 4]), + ResultSet(Mock(), []), + ResultSet(Mock(), [5, 6, 7, 8, 9]), + ] + rs = ResultSet(response_future, []) + itr = iter(rs) + self.assertListEqual(list(itr), expected) + def test_list_non_paged(self): # list access on RS for backwards-compatibility expected = list(range(10))