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

Commitf86ef3b

Browse files
committed
fix: use keyset pagination by default for /projects > 50000
Workaround forhttps://gitlab.com/gitlab-org/gitlab/-/issues/218504.Remove this in 13.1
1 parentef6181b commitf86ef3b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

‎gitlab/__init__.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
"""Wrapper for the GitLab API."""
1818

19-
from __future__importprint_function
20-
from __future__importabsolute_import
2119
importimportlib
2220
importtime
2321
importwarnings
2422

2523
importrequests
24+
importrequests.utils
2625

2726
importgitlab.config
2827
fromgitlab.constimport*# noqa
@@ -43,6 +42,8 @@
4342
"must update your GitLab URL to use https:// to avoid issues."
4443
)
4544

45+
ALLOWED_KEYSET_ENDPOINTS= ["/projects"]
46+
4647

4748
def_sanitize(value):
4849
ifisinstance(value,dict):
@@ -618,7 +619,7 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
618619
619620
Args:
620621
path (str): Path or full URL to query ('/projects' or
621-
'http://whatever/v4/api/projecs')
622+
'http://whatever/v4/api/projects')
622623
query_data (dict): Data to send as query parameters
623624
**kwargs: Extra options to send to the server (e.g. sudo, page,
624625
per_page)
@@ -642,10 +643,22 @@ def http_list(self, path, query_data=None, as_list=None, **kwargs):
642643
get_all=kwargs.pop("all",False)
643644
url=self._build_url(path)
644645

646+
order_by=kwargs.get("order_by")
647+
pagination=kwargs.get("pagination")
648+
page=kwargs.get("page")
649+
if (
650+
pathinALLOWED_KEYSET_ENDPOINTS
651+
and (notorder_byororder_by=="id")
652+
and (notpaginationorpagination=="keyset")
653+
andnotpage
654+
):
655+
kwargs["pagination"]="keyset"
656+
kwargs["order_by"]="id"
657+
645658
ifget_allisTrueandas_listisTrue:
646659
returnlist(GitlabList(self,url,query_data,**kwargs))
647660

648-
if"page"inkwargsoras_listisTrue:
661+
ifpageoras_listisTrue:
649662
# pagination requested, we return a list
650663
returnlist(GitlabList(self,url,query_data,get_next=False,**kwargs))
651664

@@ -781,7 +794,14 @@ def _query(self, url, query_data=None, **kwargs):
781794
query_data=query_dataor {}
782795
result=self._gl.http_request("get",url,query_data=query_data,**kwargs)
783796
try:
784-
self._next_url=result.links["next"]["url"]
797+
links=result.links
798+
iflinks:
799+
next_url=links["next"]["url"]
800+
else:
801+
next_url=requests.utils.parse_header_links(result.headers["links"])[
802+
0
803+
]["url"]
804+
self._next_url=next_url
785805
exceptKeyError:
786806
self._next_url=None
787807
self._current_page=result.headers.get("X-Page")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp