You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mergerequests.list(as_list=False) returns only the first page (on master branch) #534
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.
@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?
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..
Activity
gpocentek commentedon Jun 17, 2018
Thanks for the report @tardyp
This is related to #514
jouve commentedon Jun 25, 2018
@gpocentek Can you clarify the behavior of
allparameter inlist.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.
gpocentek commentedon Jun 26, 2018
@jouve the
allparameter 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 theallparameter is actually only used ifas_listis 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?
jouve commentedon Jun 26, 2018
@gpocentek nope it just made sense to me that the 2 notions were perpendicular
but you are right that compatibility is more important.
tardyp commentedon Jun 26, 2018
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()__iter__()is a shortcut for iter()eventually, one can do:
which could work for all managers, and just do what you need..