From 082231c10c9200ad56621e8a280c0e81d6197b3c Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:45:06 +0100 Subject: [PATCH] fix: no empty calls paged tasks --- influxdb_client/client/tasks_api.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/influxdb_client/client/tasks_api.py b/influxdb_client/client/tasks_api.py index 521ecebe..774a4e0a 100644 --- a/influxdb_client/client/tasks_api.py +++ b/influxdb_client/client/tasks_api.py @@ -20,7 +20,8 @@ def __iter__(self): def __next__(self): if not self.values: - self.values, self.next = self.next() + if self.next: + self.values, self.next = self.next() if not self.values: raise StopIteration return self.values.pop(0) @@ -61,18 +62,18 @@ def _find_tasks_paged(self, **kwargs): :key str org: filter tasks to a specific organization name :key str org_id: filter tasks to a specific organization ID :key int limit: the number of tasks to return in one page - :return: Tasks, Next + :return: Tasks, Next or None """ - tasks = self._service.get_tasks(**kwargs).tasks + tasks_response = self._service.get_tasks(**kwargs) + tasks = tasks_response.tasks + has_next = tasks_response.links.next is not None last_id = tasks[-1].id if tasks else None def next(): - if last_id is not None: + if has_next and last_id is not None: return self._find_tasks_paged(**{**kwargs, 'after': last_id}) else: - def func(): - raise Exception("There are no additional pages remaining for tasks.") - return [], func + return [], None return tasks, next