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

oci.pagination.list_call_get_all_results fails when using identity domain client #627

Open
pastyGRB opened this issue Feb 27, 2024 · 2 comments

Comments

@pastyGRB
Copy link

SDK version 2.123.0
Python version 3.11.4

When attempting to use oci.pagination.list_call_get_all_results with the list_groups method of oci.identity.IdentityClient, the call fails with the following error:

Traceback (most recent call last):
File "/Users/cpasternak/repos/oci_helpers/groups.py", line 48, in get_all_groups_idd
group_list=oci.pagination.list_call_get_all_results(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/cpasternak/Library/Python/3.11/lib/python/site-packages/oci/pagination/pagination_utils.py", line 218, in list_call_get_all_results
else aggregated_results.extend(call_result.data.items)
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Groups' object has no attribute 'items'

CODE:
config=valid OCI config
url="https://idcs-c2ee2b3360e24cea83df0f956fb007d5.identity.oraclecloud.com:443"
identity_domain_client = oci.identity_domains.IdentityDomainsClient(config, url)
group_list=oci.pagination.list_call_get_all_results(
identity_domain_client.list_groups,
retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY
).data

It would appear that the aggregated_results.extend function is looking for .items, but with the identity domain client, it uses the terminology .resources (not .items)

@adizohar
Copy link
Member

adizohar commented Feb 27, 2024

Until it fixed, you can use below functions I wrote in showoci to deal with paginations:

    ##########################################################################
    # Pagination main call
    ##########################################################################
    def list_call_get_all_results(list_func_ref, *list_func_args, **list_func_kwargs):

        aggregated_results = []
        for call_result in list_call_get_all_results_generator_domains(list_func_ref, *list_func_args, **list_func_kwargs):
            aggregated_results.extend(call_result.data.resources)
            final_response = oci.Response(call_result.status, call_result.headers, aggregated_results, call_result.request)
        return final_response

    ##########################################################################
    # Pagination result generator
    ##########################################################################
    def list_call_get_all_results_generator_domains(list_func_ref, *list_func_args, **list_func_kwargs):

        keep_paginating = True

        while keep_paginating:
            call_result = oci.retry.DEFAULT_RETRY_STRATEGY.make_retrying_call(list_func_ref, *list_func_args, **list_func_kwargs)
            yield call_result

            start_index = call_result.data.start_index
            total_results = call_result.data.total_results
            items_per_page = call_result.data.items_per_page
            next_index = start_index + items_per_page

            if next_index < total_results:
                list_func_kwargs['start_index'] = next_index
            else:
                keep_paginating = False

@pastyGRB
Copy link
Author

Also opened Oracle SR: [3-35893215011]

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

2 participants