Skip to content

Commit 7c71d5d

Browse files
nejchJohnVillalovos
authored andcommitted
fix: add get_all param (and --get-all) to allow passing all to API
1 parent 0549afa commit 7c71d5d

19 files changed

+158
-100
lines changed

docs/api-usage-advanced.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ supplying the ``obey_rate_limit`` argument.
9797
import requests
9898
9999
gl = gitlab.gitlab(url, token, api_version=4)
100-
gl.projects.list(all=True, obey_rate_limit=False)
100+
gl.projects.list(get_all=True, obey_rate_limit=False)
101101
102102
If you do not disable the rate-limiting feature, you can supply a custom value
103103
for ``max_retries``; by default, this is set to 10. To retry without bound when
@@ -110,7 +110,7 @@ throttled, you can set this parameter to -1. This parameter is ignored if
110110
import requests
111111
112112
gl = gitlab.gitlab(url, token, api_version=4)
113-
gl.projects.list(all=True, max_retries=12)
113+
gl.projects.list(get_all=True, max_retries=12)
114114
115115
.. warning::
116116

@@ -133,7 +133,7 @@ is raised for these errors.
133133
import requests
134134
135135
gl = gitlab.gitlab(url, token, api_version=4)
136-
gl.projects.list(all=True, retry_transient_errors=True)
136+
gl.projects.list(get_all=True, retry_transient_errors=True)
137137
138138
The default ``retry_transient_errors`` can also be set on the ``Gitlab`` object
139139
and overridden by individual API calls.
@@ -143,8 +143,8 @@ and overridden by individual API calls.
143143
import gitlab
144144
import requests
145145
gl = gitlab.gitlab(url, token, api_version=4, retry_transient_errors=True)
146-
gl.projects.list(all=True) # retries due to default value
147-
gl.projects.list(all=True, retry_transient_errors=False) # does not retry
146+
gl.projects.list(get_all=True) # retries due to default value
147+
gl.projects.list(get_all=True, retry_transient_errors=False) # does not retry
148148
149149
Timeout
150150
-------

docs/api-usage.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Examples:
110110
111111
.. warning::
112112
Calling ``list()`` without any arguments will by default not return the complete list
113-
of items. Use either the ``all=True`` or ``iterator=True`` parameters to get all the
113+
of items. Use either the ``get_all=True`` or ``iterator=True`` parameters to get all the
114114
items when using listing methods. See the :ref:`pagination` section for more
115115
information.
116116

@@ -144,7 +144,7 @@ Some objects also provide managers to access related GitLab resources:
144144
145145
# list the issues for a project
146146
project = gl.projects.get(1)
147-
issues = project.issues.list(all=True)
147+
issues = project.issues.list(get_all=True)
148148
149149
python-gitlab allows to send any data to the GitLab server when making queries.
150150
In case of invalid or missing arguments python-gitlab will raise an exception
@@ -314,13 +314,14 @@ listing methods support the ``page`` and ``per_page`` parameters:
314314

315315
The first page is page 1, not page 0.
316316

317-
By default GitLab does not return the complete list of items. Use the ``all``
317+
By default GitLab does not return the complete list of items. Use the ``get_all``
318318
parameter to get all the items when using listing methods:
319319

320320
.. code-block:: python
321321
322-
all_groups = gl.groups.list(all=True)
323-
all_owned_projects = gl.projects.list(owned=True, all=True)
322+
all_groups = gl.groups.list(get_all=True)
323+
324+
all_owned_projects = gl.projects.list(owned=True, get_all=True)
324325
325326
You can define the ``per_page`` value globally to avoid passing it to every
326327
``list()`` method call:

docs/cli-examples.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ List all the projects:
7676

7777
.. code-block:: console
7878
79-
$ gitlab project list --all
79+
$ gitlab project list --get-all
8080
8181
List all projects of a group:
8282

8383
.. code-block:: console
8484
85-
$ gitlab group-project list --all --group-id 1
85+
$ gitlab group-project list --get-all --group-id 1
8686
8787
List all projects of a group and its subgroups:
8888

8989
.. code-block:: console
9090
91-
$ gitlab group-project list --all --include-subgroups true --group-id 1
91+
$ gitlab group-project list --get-all --include-subgroups true --group-id 1
9292
9393
Limit to 5 items per request, display the 1st page only
9494

docs/faq.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refr
4848
You are most likely trying to access an attribute that was not returned
4949
by the server on the second request. Please look at the documentation in
5050
:ref:`object_attributes` to see how to avoid this.
51+
52+
I passed ``all=True`` (or ``--all`` via the CLI) to the API and I still cannot see all items returned.
53+
Use ``get_all=True`` (or ``--get-all`` via the CLI). See :ref:`pagination` for more details.

docs/gl_objects/commits.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ results::
2727
commits = project.commits.list(ref_name='my_branch')
2828
commits = project.commits.list(since='2016-01-01T00:00:00Z')
2929

30-
.. note::
30+
List all commits for a project (see :ref:`pagination`) on all branches:
3131

32-
The available ``all`` listing argument conflicts with the python-gitlab
33-
argument. Use ``query_parameters`` to avoid the conflict::
34-
35-
commits = project.commits.list(all=True,
36-
query_parameters={'ref_name': 'my_branch'})
32+
commits = project.commits.list(get_all=True, all=True)
3733

3834
Create a commit::
3935

docs/gl_objects/groups.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ List only direct group members::
271271
List the group members recursively (including inherited members through
272272
ancestor groups)::
273273

274-
members = group.members_all.list(all=True)
274+
members = group.members_all.list(get_all=True)
275275

276276
Get only direct group member::
277277

docs/gl_objects/projects.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Results can also be sorted using the following parameters:
4040
::
4141

4242
# List all projects (default 20)
43-
projects = gl.projects.list(all=True)
43+
projects = gl.projects.list(get_all=True)
4444
# Archived projects
4545
projects = gl.projects.list(archived=1)
4646
# Limit to projects with a defined visibility
@@ -559,7 +559,7 @@ List only direct project members::
559559
List the project members recursively (including inherited members through
560560
ancestor groups)::
561561

562-
members = project.members_all.list(all=True)
562+
members = project.members_all.list(get_all=True)
563563

564564
Search project members matching a query string::
565565

docs/gl_objects/users.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,5 @@ Get the users activities::
454454

455455
activities = gl.user_activities.list(
456456
query_parameters={'from': '2018-07-01'},
457-
all=True, iterator=True)
457+
get_all=True,
458+
)

gitlab/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def http_list(
857857
Returns:
858858
A list of the objects returned by the server. If `iterator` is
859859
True and no pagination-related arguments (`page`, `per_page`,
860-
`all`) are defined then a GitlabList object (generator) is returned
860+
`get_all`) are defined then a GitlabList object (generator) is returned
861861
instead. This object will make API calls when needed to fetch the
862862
next items from the server.
863863
@@ -884,7 +884,13 @@ def http_list(
884884
category=DeprecationWarning,
885885
)
886886

887-
get_all = kwargs.pop("all", None)
887+
# Provide a `get_all`` param to avoid clashes with `all` API attributes.
888+
get_all = kwargs.pop("get_all", None)
889+
890+
if get_all is None:
891+
# For now, keep `all` without deprecation.
892+
get_all = kwargs.pop("all", None)
893+
888894
url = self._build_url(path)
889895

890896
page = kwargs.get("page")
@@ -902,7 +908,7 @@ def http_list(
902908

903909
def should_emit_warning() -> bool:
904910
# No warning is emitted if any of the following conditions apply:
905-
# * `all=False` was set in the `list()` call.
911+
# * `get_all=False` was set in the `list()` call.
906912
# * `page` was set in the `list()` call.
907913
# * GitLab did not return the `x-per-page` header.
908914
# * Number of items received is less than per-page value.
@@ -927,12 +933,12 @@ def should_emit_warning() -> bool:
927933
total_items = "many" if gl_list.total is None else gl_list.total
928934
utils.warn(
929935
message=(
930-
f"Calling a `list()` method without specifying `all=True` or "
936+
f"Calling a `list()` method without specifying `get_all=True` or "
931937
f"`iterator=True` will return a maximum of {gl_list.per_page} items. "
932938
f"Your query returned {len(items)} of {total_items} items. See "
933939
f"{_PAGINATION_URL} for more details. If this was done intentionally, "
934940
f"then this warning can be supressed by adding the argument "
935-
f"`all=False` to the `list()` call."
941+
f"`get_all=False` to the `list()` call."
936942
),
937943
category=UserWarning,
938944
)

gitlab/v4/cli.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,18 @@ def _populate_sub_parser_by_class(
240240

241241
sub_parser_action.add_argument("--page", required=False, type=int)
242242
sub_parser_action.add_argument("--per-page", required=False, type=int)
243-
sub_parser_action.add_argument("--all", required=False, action="store_true")
243+
sub_parser_action.add_argument(
244+
"--get-all",
245+
required=False,
246+
action="store_true",
247+
help="Return all items from the server, without pagination.",
248+
)
249+
sub_parser_action.add_argument(
250+
"--all",
251+
required=False,
252+
action="store_true",
253+
help="Deprecated. Use --get-all instead.",
254+
)
244255

245256
if action_name == "delete":
246257
if cls._id_attr is not None:

0 commit comments

Comments
 (0)