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:
Stevenson Michel
2026-06-24 09:56:26 -04:00
committed by GitHub
parent f25e436bef
commit 17dc7f898a

View File

@@ -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: