From 17dc7f898a03d17bd52907813fe507194eefafa4 Mon Sep 17 00:00:00 2001 From: Stevenson Michel Date: Wed, 24 Jun 2026 09:56:26 -0400 Subject: [PATCH] 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. --- awx_collection/plugins/module_utils/controller_api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py index b2d266e23d..89e2600eb1 100644 --- a/awx_collection/plugins/module_utils/controller_api.py +++ b/awx_collection/plugins/module_utils/controller_api.py @@ -438,7 +438,7 @@ class ControllerAPIModule(ControllerModule): raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response)) 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.') while next_page is not None: @@ -493,8 +493,11 @@ class ControllerAPIModule(ControllerModule): fail_msg += ', detail: {0}'.format(response['json']['detail']) self.fail_json(msg=fail_msg) - if 'count' not in response['json'] or 'results' not in response['json']: - self.fail_json(msg="The endpoint did not provide count and results") + if 'results' not in response['json']: + 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 allow_none: