Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination "resp.has_next" is always true ? #435

Open
mleo40 opened this issue Jan 29, 2025 · 1 comment
Open

Pagination "resp.has_next" is always true ? #435

mleo40 opened this issue Jan 29, 2025 · 1 comment

Comments

@mleo40
Copy link

mleo40 commented Jan 29, 2025

I am very new to this, but my while loop based on your example for pagination seems to always return true.

I think it's because resp always has a "ref=next", even if that url referenced is the object itself.

https://xyz.server.com/api/v1/users?after=XYXYXYXYXXYXY&limit=1; rel="next"

is returned from : https://xyz.server.com/api/v1/users?limit=1

  1. is resp.has_next in reference to rel="next"
  2. if so, this is an endless loop since even 1 item returned from limit=1 has a has_next value

query_parameters = {'limit': '1'}
users, resp, err = await client.list_users(query_parameters)

Check if there more pages follow

if resp.has_next():
users, err = await resp.next() # Returns list of 1 user after the last retrieved user

Iterate through all of the rest of the pages

while resp.has_next():
users, err = await resp.next()

Do stuff with users in users

print(resp.has_next()) # False
try:
await resp.next()
except StopAsyncIteration:

Handle Exception raised

@mleo40
Copy link
Author

mleo40 commented Jan 30, 2025

Actually what we've also discovered is that the first list_users returns objects but on the first "next" page we get back dict, which breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant