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 · 2 comments · May be fixed by #438
Open

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

mleo40 opened this issue Jan 29, 2025 · 2 comments · May be fixed by #438
Assignees

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.

@dtump
Copy link

dtump commented Feb 26, 2025

I noticed the same with list_groups. Actually the first and second batch are okta.models.group.Group objects, from the third it's a dict. When I print the type and list groups with limit=1, then I get:

<class 'okta.models.group.Group'>
<class 'okta.models.group.Group'>
<class 'dict'>

So I added this to my code:

                for group in groups_list:
                    # Weird Okta SDK behavior: it returns objects at the first and second request, and dicts at the third request
                    if hasattr(group, 'as_dict'):
                        groups.append(group.as_dict())
                    elif isinstance(group, dict):
                        groups.append(group)

This feels very crappy, but I have no other solution at this point :(

comrumino pushed a commit to comrumino/okta-sdk-python that referenced this issue Mar 14, 2025
… next_response has a type consistent with the previous response.

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

Successfully merging a pull request may close this issue.

4 participants