Skip to content

Commit 082231c

Browse files
committed
fix: no empty calls paged tasks
1 parent f72b3cc commit 082231c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

influxdb_client/client/tasks_api.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def __iter__(self):
2020

2121
def __next__(self):
2222
if not self.values:
23-
self.values, self.next = self.next()
23+
if self.next:
24+
self.values, self.next = self.next()
2425
if not self.values:
2526
raise StopIteration
2627
return self.values.pop(0)
@@ -61,18 +62,18 @@ def _find_tasks_paged(self, **kwargs):
6162
:key str org: filter tasks to a specific organization name
6263
:key str org_id: filter tasks to a specific organization ID
6364
:key int limit: the number of tasks to return in one page
64-
:return: Tasks, Next
65+
:return: Tasks, Next or None
6566
"""
66-
tasks = self._service.get_tasks(**kwargs).tasks
67+
tasks_response = self._service.get_tasks(**kwargs)
68+
tasks = tasks_response.tasks
6769

70+
has_next = tasks_response.links.next is not None
6871
last_id = tasks[-1].id if tasks else None
6972
def next():
70-
if last_id is not None:
73+
if has_next and last_id is not None:
7174
return self._find_tasks_paged(**{**kwargs, 'after': last_id})
7275
else:
73-
def func():
74-
raise Exception("There are no additional pages remaining for tasks.")
75-
return [], func
76+
return [], None
7677

7778
return tasks, next
7879

0 commit comments

Comments
 (0)