GeezerVison is showing github.com — fix: add `get_all` param (and `--get-all`) to allow passing `all` to API · python-gitlab/python-gitlab@7c71d5d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/api-usage-advanced.rst +5-5Lines changed: 5 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,7 @@ supplying the ``obey_rate_limit`` argument. | 97 | 97 | import requests | 98 | 98 |
| 99 | 99 | 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) | 101 | 101 |
| 102 | 102 | If you do not disable the rate-limiting feature, you can supply a custom value | 103 | 103 | 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 | 110 | 110 | import requests | 111 | 111 |
| 112 | 112 | 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) | 114 | 114 |
| 115 | 115 | .. warning:: | 116 | 116 |
| @@ -133,7 +133,7 @@ is raised for these errors. | 133 | 133 | import requests | 134 | 134 |
| 135 | 135 | 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) | 137 | 137 |
| 138 | 138 | The default ``retry_transient_errors`` can also be set on the ``Gitlab`` object | 139 | 139 | and overridden by individual API calls. | @@ -143,8 +143,8 @@ and overridden by individual API calls. | 143 | 143 | import gitlab | 144 | 144 | import requests | 145 | 145 | 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 | 148 | 148 |
| 149 | 149 | Timeout | 150 | 150 | ------- | |
Collapse file Copy file name to clipboardExpand all lines: docs/api-usage.rst +6-5Lines changed: 6 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -110,7 +110,7 @@ Examples: | 110 | 110 |
| 111 | 111 | .. warning:: | 112 | 112 | 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 | 114 | 114 | items when using listing methods. See the :ref:`pagination` section for more | 115 | 115 | information. | 116 | 116 |
| @@ -144,7 +144,7 @@ Some objects also provide managers to access related GitLab resources: | 144 | 144 |
| 145 | 145 | # list the issues for a project | 146 | 146 | project = gl.projects.get(1) | 147 | | - issues = project.issues.list(all=True) | | 147 | + issues = project.issues.list(get_all=True) | 148 | 148 |
| 149 | 149 | python-gitlab allows to send any data to the GitLab server when making queries. | 150 | 150 | 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: | 314 | 314 |
| 315 | 315 | The first page is page 1, not page 0. | 316 | 316 |
| 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`` | 318 | 318 | parameter to get all the items when using listing methods: | 319 | 319 |
| 320 | 320 | .. code-block:: python | 321 | 321 |
| 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) | 324 | 325 |
| 325 | 326 | You can define the ``per_page`` value globally to avoid passing it to every | 326 | 327 | ``list()`` method call: | |
Collapse file Copy file name to clipboardExpand all lines: docs/cli-examples.rst +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -76,19 +76,19 @@ List all the projects: | 76 | 76 |
| 77 | 77 | .. code-block:: console | 78 | 78 |
| 79 | | - $ gitlab project list --all | | 79 | + $ gitlab project list --get-all | 80 | 80 |
| 81 | 81 | List all projects of a group: | 82 | 82 |
| 83 | 83 | .. code-block:: console | 84 | 84 |
| 85 | | - $ gitlab group-project list --all --group-id 1 | | 85 | + $ gitlab group-project list --get-all --group-id 1 | 86 | 86 |
| 87 | 87 | List all projects of a group and its subgroups: | 88 | 88 |
| 89 | 89 | .. code-block:: console | 90 | 90 |
| 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 | 92 | 92 |
| 93 | 93 | Limit to 5 items per request, display the 1st page only | 94 | 94 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/faq.rst +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -48,3 +48,6 @@ I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refr | 48 | 48 | You are most likely trying to access an attribute that was not returned | 49 | 49 | by the server on the second request. Please look at the documentation in | 50 | 50 | :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. |
Collapse file Copy file name to clipboardExpand all lines: docs/gl_objects/commits.rst +2-6Lines changed: 2 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,13 +27,9 @@ results:: | 27 | 27 | commits = project.commits.list(ref_name='my_branch') | 28 | 28 | commits = project.commits.list(since='2016-01-01T00:00:00Z') | 29 | 29 |
| 30 | | -.. note:: | | 30 | +List all commits for a project (see :ref:`pagination`) on all branches: | 31 | 31 |
| 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) | 37 | 33 |
| 38 | 34 | Create a commit:: | 39 | 35 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/gl_objects/groups.rst +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -271,7 +271,7 @@ List only direct group members:: | 271 | 271 | List the group members recursively (including inherited members through | 272 | 272 | ancestor groups):: | 273 | 273 |
| 274 | | - members = group.members_all.list(all=True) | | 274 | + members = group.members_all.list(get_all=True) | 275 | 275 |
| 276 | 276 | Get only direct group member:: | 277 | 277 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/gl_objects/projects.rst +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,7 @@ Results can also be sorted using the following parameters: | 40 | 40 | :: | 41 | 41 |
| 42 | 42 | # List all projects (default 20) | 43 | | - projects = gl.projects.list(all=True) | | 43 | + projects = gl.projects.list(get_all=True) | 44 | 44 | # Archived projects | 45 | 45 | projects = gl.projects.list(archived=1) | 46 | 46 | # Limit to projects with a defined visibility | @@ -559,7 +559,7 @@ List only direct project members:: | 559 | 559 | List the project members recursively (including inherited members through | 560 | 560 | ancestor groups):: | 561 | 561 |
| 562 | | - members = project.members_all.list(all=True) | | 562 | + members = project.members_all.list(get_all=True) | 563 | 563 |
| 564 | 564 | Search project members matching a query string:: | 565 | 565 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/gl_objects/users.rst +2-1Lines changed: 2 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -454,4 +454,5 @@ Get the users activities:: | 454 | 454 |
| 455 | 455 | activities = gl.user_activities.list( | 456 | 456 | query_parameters={'from': '2018-07-01'}, | 457 | | - all=True, iterator=True) | | 457 | + get_all=True, | | 458 | + ) |
Collapse file Copy file name to clipboardExpand all lines: gitlab/client.py +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -857,7 +857,7 @@ def http_list( | 857 | 857 | Returns: | 858 | 858 | A list of the objects returned by the server. If `iterator` is | 859 | 859 | 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 | 861 | 861 | instead. This object will make API calls when needed to fetch the | 862 | 862 | next items from the server. | 863 | 863 |
| @@ -884,7 +884,13 @@ def http_list( | 884 | 884 | category=DeprecationWarning, | 885 | 885 | ) | 886 | 886 |
| 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 | + | 888 | 894 | url = self._build_url(path) | 889 | 895 |
| 890 | 896 | page = kwargs.get("page") | @@ -902,7 +908,7 @@ def http_list( | 902 | 908 |
| 903 | 909 | def should_emit_warning() -> bool: | 904 | 910 | # 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. | 906 | 912 | # * `page` was set in the `list()` call. | 907 | 913 | # * GitLab did not return the `x-per-page` header. | 908 | 914 | # * Number of items received is less than per-page value. | @@ -927,12 +933,12 @@ def should_emit_warning() -> bool: | 927 | 933 | total_items = "many" if gl_list.total is None else gl_list.total | 928 | 934 | utils.warn( | 929 | 935 | message=( | 930 | | - f"Calling a `list()` method without specifying `all=True` or " | | 936 | + f"Calling a `list()` method without specifying `get_all=True` or " | 931 | 937 | f"`iterator=True` will return a maximum of {gl_list.per_page} items. " | 932 | 938 | f"Your query returned {len(items)} of {total_items} items. See " | 933 | 939 | f"{_PAGINATION_URL} for more details. If this was done intentionally, " | 934 | 940 | 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." | 936 | 942 | ), | 937 | 943 | category=UserWarning, | 938 | 944 | ) | |
Collapse file Copy file name to clipboardExpand all lines: gitlab/v4/cli.py +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -240,7 +240,18 @@ def _populate_sub_parser_by_class( | 240 | 240 |
| 241 | 241 | sub_parser_action.add_argument("--page", required=False, type=int) | 242 | 242 | 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 | + ) | 244 | 255 |
| 245 | 256 | if action_name == "delete": | 246 | 257 | if cls._id_attr is not None: | |
|