Skip to content

Commit

Permalink
Handle the pagination Link headers for _list requests
Browse files Browse the repository at this point in the history
The patchwork REST API defaults to sending a maximum of 30 items for API
requests which return a list. This makes pwclient list fail to return more
than 30 items when using the REST API.

To handle this, the API includes 'Link' headers in the response which
indicate whether there is more data and what URL the data is available at.

Processing the Link header is done automatically by the requests library.
Handle this in the _list implementation by checking whether the response
had a 'next' header, and request that data as well. This allows the
pwclient to list everything instead of being limited to 30 patches.

Signed-off-by: Jacob Keller <[email protected]>
  • Loading branch information
jacob-keller committed Oct 27, 2023
1 parent 4cb4036 commit 4f1adaa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pwclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,17 @@ def _list(
r = self._get(url, params)
if r.status_code == http.HTTPStatus.NOT_FOUND:
return []
return r.json()

items = r.json()

while 'next' in r.links:
r = self._get(r.links['next']['url'], params)
if r.status_code == http.HTTPStatus.NOT_FOUND:
break

items += r.json()

return items

# project

Expand Down

0 comments on commit 4f1adaa

Please sign in to comment.