Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit971a617

Browse files
fix: handle situation where GitLab does not return values
If a query returns more than 10,000 records than the following valuesare NOT returned: x.total_pages x.totalModify the code to allow no value to be set for these values. If thereis not a value returned the functions will now return None.https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headersCloses#1686
1 parent83dcabf commit971a617

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

‎docs/api-usage.rst‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,17 @@ The generator exposes extra listing information as received from the server:
265265
* ``prev_page``: if ``None`` the current page is the first one
266266
* ``next_page``: if ``None`` the current page is the last one
267267
* ``per_page``: number of items per page
268-
* ``total_pages``: total number of pages available
269-
* ``total``: total number of items in the list
268+
* ``total_pages``: total number of pages available. This may be a ``None`` value.
269+
* ``total``: total number of items in the list. This may be a ``None`` value.
270+
271+
..note::
272+
273+
``total_pages`` and ``total`` may have a value of ``None``. For performance
274+
reasons, if a query returns more than 10,000 records, GitLab doesn’t return
275+
any value for ``total_pages`` or ``total``.
276+
277+
For more information see:
278+
https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
270279

271280
Sudo
272281
====

‎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
returnself._list.per_page
289289

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

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

‎gitlab/client.py‎

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

968968
@property
969-
deftotal_pages(self)->int:
969+
deftotal_pages(self)->Optional[int]:
970970
"""The total number of pages."""
971-
ifTYPE_CHECKING:
972-
assertself._total_pagesisnotNone
971+
ifself._total_pagesisNone:
972+
# NOTE(jlvillal): When a query returns more than 10,000 items, GitLab
973+
# doesn't return the header for this value. So we return None.
974+
# https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
975+
returnNone
973976
returnint(self._total_pages)
974977

975978
@property
976-
deftotal(self)->int:
979+
deftotal(self)->Optional[int]:
977980
"""The total number of items."""
978-
ifTYPE_CHECKING:
979-
assertself._totalisnotNone
981+
ifself._totalisNone:
982+
# NOTE(jlvillal): When a query returns more than 10,000 items, GitLab
983+
# doesn't return the header for this value. So we return None.
984+
# https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers
985+
returnNone
980986
returnint(self._total)
981987

982988
def__iter__(self)->"GitlabList":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp