cloudfoundry-community/cf-python-client

Generator object for service_credential_bindings.details() returns pagination error

jimconner opened this issue · 3 comments

I suspect that this is another case along the same lines as issue #115

I'm trying to fetch the .details() for a service_credential binding which returns a generator object which cannot be iterated through as it generates errors in the _paginate function.

for service_instance in cfClient.v3.service_instances.list(**{'service_plan_guids': service_plan_guid}):
    for binding in service_instance.service_credential_bindings():
        print(binding.details())
        for thing in binding.details():
                  print(thing)

... which results in ...

<generator object EntityManager._paginate at 0x113a42190>
Traceback (most recent call last):
  File "/some/dir/path/cf-utils/./services-finder.py", line 50, in <module>
    for thing in binding.details():
  File "/some/dir/path/.pyenv/versions/3.9.2/lib/python3.9/site-packages/cloudfoundry_client/v3/entities.py", line 160, in _paginate
    for resource in response_json["resources"]:
KeyError: 'resources'

As with #115 the 'details' that are being returned is a single dict object and therefore doesn't need to be paginated in the output.

I tried to work out how to fix this myself based on the changes that were made from #115, but sadly I failed. As such, I'm raising the issue in the hope that some kind soul can implement a suitable fix.

@jimconner thank for the feedback.

I implemented a fix... Would you mind testing it and telling me if it is ok before doing a fresh release?

Best regards

Thank you very much for the fast turnaround on the fix @antechrestos - I've now tested it out and can confirm that it's working perfectly for my needs. I can now access the detail that I needed via binding.details()['credentials']['username'].

Thanks you again for your superb work on this library. I use it on a daily basis to scrape info from the CF API. My life would be a lot more difficult without it. Cheers!!

@jimconner cheers back 😃

I've juste released a fesh v1.21.0 release