Skip to content

Commit c79e061

Browse files
fix: handle situation where gitlab.com does not return values
If a query returns more than 10,000 records than the following values are NOT returned: x.total_pages x.total Modify the code to allow no value to be set for these values. If there is not a value returned the functions will now return None. https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers Closes #1686
1 parent 83dcabf commit c79e061

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎gitlab/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ def per_page(self) -> int:
288288
return self._list.per_page
289289

290290
@property
291-
def total_pages(self) -> int:
291+
def total_pages(self) -> Optional[int]:
292292
"""The total number of pages."""
293293
return self._list.total_pages
294294

295295
@property
296-
def total(self) -> int:
296+
def total(self) -> Optional[int]:
297297
"""The total number of items."""
298298
return self._list.total
299299

‎gitlab/client.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,17 +966,25 @@ def per_page(self) -> int:
966966
return int(self._per_page)
967967

968968
@property
969-
def total_pages(self) -> int:
969+
def total_pages(self) -> Optional[int]:
970970
"""The total number of pages."""
971-
if TYPE_CHECKING:
972-
assert self._total_pages is not None
971+
if self._total_pages is None:
972+
# NOTE(jlvillal): When more than 10,000 items are returned on
973+
# https://gitlab.com/ then the header for this value will not be
974+
# returned. So we return None.
975+
# https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
976+
return None
973977
return int(self._total_pages)
974978

975979
@property
976-
def total(self) -> int:
980+
def total(self) -> Optional[int]:
977981
"""The total number of items."""
978-
if TYPE_CHECKING:
979-
assert self._total is not None
982+
if self._total is None:
983+
# NOTE(jlvillal): When more than 10,000 items are returned on
984+
# https://gitlab.com/ then the header for this value will not be
985+
# returned. So we return None.
986+
# https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
987+
return None
980988
return int(self._total)
981989

982990
def __iter__(self) -> "GitlabList":

0 commit comments

Comments
 (0)