Skip to content

mergerequests.list(as_list=False) returns only the first page (on master branch) #534

Closed

Description

@tardyp

Description of the problem, including code/CLI snippet

Following snippet only fetches the first page.

p = gl.projects.get("gitlab-org/gitlab-ce")
all_mrs = p.mergerequests.list(state="all", order_by="updated_at", as_list=False)
for mr in all_mrs:
    print(all_mrs.current_page, all_mrs.total_pages)

Expected Behavior

should fetch all pages

Actual Behavior

only display current_page = 1, while it should go through 994 pages.

works as expected on pypi version.

Specifications

  • python-gitlab version: master
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): gitlab.com

Activity

  1. gpocentek commented on Jun 17, 2018

    @gpocentek
    Contributor

    Thanks for the report @tardyp

    This is related to #514

  2. jouve commented on Jun 25, 2018

    @jouve
    Contributor

    @gpocentek Can you clarify the behavior of all parameter in list.

    In the exemple of tardyp, all is not given (so it default to False), so it seems to me that the correct behaviour is to return only first page.

  3. gpocentek commented on Jun 26, 2018

    @gpocentek
    Contributor

    @jouve the all parameter comes from the python-gitlab v3 API where the generator didn't exist. It was used to retrieve all the items in the list, as you can expect. For v4 the all parameter is actually only used if as_list is True.

    The change in your MR makes sense I guess, but it also broke the compatibility with older python-gitlab version. I wonder if there is a real interest in getting a generator for a single page, since it would only be used to loop through an already existing list. But maybe you have something in mind that didn't cross mine?

  4. jouve commented on Jun 26, 2018

    @jouve
    Contributor

    @gpocentek nope it just made sense to me that the 2 notions were perpendicular

    • all vs one page
    • list vs generator

    but you are right that compatibility is more important.

  5. tardyp commented on Jun 26, 2018

    @tardyp
    ContributorAuthor

    I agree that the list API is not very intuitive and the results of several API attempt iterations (no blame for that).

    Most new python library always return iterator. if you really want a list, then you just call list()
    e.g. in py3 range returns iterator, if you want old behaviour, you just do:

    l = list(range(10))

    If I were to redesign the API to be more pythonic, maybe we could just add an iter() method, and even an __iter__ method()

    • list() always return a list (has all=False by default, and as_list=True)
    • iter() always return a generator (and has paging and filtering arguments for those who cares)
    • __iter__() is a shortcut for iter()

    eventually, one can do:

    for project in gl.projects:
         print(project)
    

    which could work for all managers, and just do what you need..

  6. locked as resolved and limited conversation to collaborators on Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions