Skip to content

Commit 585e3a8

Browse files
Helen KoikeJohnVillalovos
Helen Koike
authored andcommitted
fix(client): regression - do not automatically get_next if page=# and
iterator=True/as_list=False are used This fix a regression introduced on commit 1339d64 If page is used, then get_next should be false. This was found on the mesa ci project, after upgrading the python-gitlab version, the script that monitors the ci was getting killed by consuming too much memory.
1 parent 3c7c7fc commit 585e3a8

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/api-usage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ The generator exposes extra listing information as received from the server:
393393
Prior to python-gitlab 3.6.0 the argument ``as_list`` was used instead of
394394
``iterator``. ``as_list=False`` is the equivalent of ``iterator=True``.
395395

396+
.. note::
397+
If ``page`` and ``iterator=True`` are used together, the latter is ignored.
398+
396399
Sudo
397400
====
398401

gitlab/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def http_list(
929929

930930
page = kwargs.get("page")
931931

932-
if iterator:
932+
if iterator and page is None:
933933
# Generator requested
934934
return GitlabList(self, url, query_data, **kwargs)
935935

tests/unit/test_gitlab_http_methods.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,18 @@ def test_list_request(gl):
542542
assert responses.assert_call_count(url, 3) is True
543543

544544

545+
@responses.activate
546+
def test_list_request_page_and_iterator(gl):
547+
response_dict = copy.deepcopy(large_list_response)
548+
response_dict["match"] = [responses.matchers.query_param_matcher({"page": "1"})]
549+
responses.add(**response_dict)
550+
551+
result = gl.http_list("/projects", iterator=True, page=1)
552+
assert isinstance(result, list)
553+
assert len(result) == 20
554+
assert len(responses.calls) == 1
555+
556+
545557
large_list_response = {
546558
"method": responses.GET,
547559
"url": "http://localhost/api/v4/projects",

0 commit comments

Comments
 (0)