mirror of
https://github.com/ansible/awx.git
synced 2026-06-25 16:38:03 -02:30
Fix: handle cursor-paginated responses in get_one() (#16521)
* Fix: handle cursor-paginated API responses in get_one() DAB PR #1025 switched role_team_assignments and role_user_assignments endpoints from PageNumberPagination to CursorPagination. Cursor pagination returns {results, next, previous} without a count field, causing get_one() to fail with "The endpoint did not provide count and results". When the response includes results but no count, infer count from len(results). Also guard get_all_endpoint() against missing count.
This commit is contained in:
@@ -438,7 +438,7 @@ class ControllerAPIModule(ControllerModule):
|
|||||||
raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response))
|
raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response))
|
||||||
next_page = response['json']['next']
|
next_page = response['json']['next']
|
||||||
|
|
||||||
if response['json']['count'] > 10000:
|
if response['json'].get('count', 0) > 10000:
|
||||||
self.fail_json(msg='The number of items being queried for is higher than 10,000.')
|
self.fail_json(msg='The number of items being queried for is higher than 10,000.')
|
||||||
|
|
||||||
while next_page is not None:
|
while next_page is not None:
|
||||||
@@ -493,8 +493,11 @@ class ControllerAPIModule(ControllerModule):
|
|||||||
fail_msg += ', detail: {0}'.format(response['json']['detail'])
|
fail_msg += ', detail: {0}'.format(response['json']['detail'])
|
||||||
self.fail_json(msg=fail_msg)
|
self.fail_json(msg=fail_msg)
|
||||||
|
|
||||||
if 'count' not in response['json'] or 'results' not in response['json']:
|
if 'results' not in response['json']:
|
||||||
self.fail_json(msg="The endpoint did not provide count and results")
|
self.fail_json(msg="The endpoint did not provide a results list")
|
||||||
|
|
||||||
|
if 'count' not in response['json']:
|
||||||
|
response['json']['count'] = len(response['json']['results'])
|
||||||
|
|
||||||
if response['json']['count'] == 0:
|
if response['json']['count'] == 0:
|
||||||
if allow_none:
|
if allow_none:
|
||||||
|
|||||||
Reference in New Issue
Block a user