Skip to content

Commit 85ecff4

Browse files
committed
[sc-98256] Handling offset pagination on APIs returning a list
1 parent 3c0a89b commit 85ecff4

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

python-lib/pagination.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, config=None, skip_key=None, limit_key=None, total_key=None, n
2424
self.is_paging_started = None
2525
self.next_page_number = None
2626
self.params_must_be_blanked = False
27+
self.data_is_list = None
2728

2829
def configure_paging(self, config=None, skip_key=None, limit_key=None, total_key=None, next_page_key=None, url=None, pagination_type="na"):
2930
config = {} if config is None else config
@@ -62,7 +63,9 @@ def update_next_page(self, data, response_links=None):
6263
if next_page_url:
6364
self.next_page_url = next_page_url
6465
self.params_must_be_blanked = True
66+
self.data_is_list = False
6567
if isinstance(data, list):
68+
self.data_is_list = True
6669
batch_size = len(data)
6770
self.records_to_skip = self.records_to_skip + batch_size
6871
if batch_size == 0:
@@ -120,6 +123,8 @@ def has_next_page(self):
120123
# There is a counting key and we already know the last batch was not empty
121124
return True
122125
else:
126+
if self.data_is_list:
127+
return True
123128
# No way to know if the last batch was empty so we stop here
124129
return False
125130
return False

0 commit comments

Comments
 (0)