-
Notifications
You must be signed in to change notification settings - Fork 154
Description
Background
When attempting to paginate, and setting the parameter includeResponse=True
for response.next()
:
while response.has_next(): logger.debug("Response from okta has next page") more_returned_data: list[OktaObject] more_returned_data, error, response = await response.next( includeResponse=True ) returned_data.extend(more_returned_data)
Issue
If self.get_next().__anext__()
(line 137) within response.next()
returns an error, and includeResponse
is True
, the function will not respond with a tuple defining a response.
See comments in code
#If this function call returns an error
next_page, error, next_response = await self.get_next().__anext__()
# The code never checks if includeResponse==True.
if error:
return (None, error)
if self._type is not None:
result = []
for item in next_page:
result.append(self._type(item) if self._type in MODELS_NOT_TO_CAMEL_CASE
else self._type(APIClient.form_response_body(item)))
if includeResponse:
#This is the an example of how the function should respond if includeResponse==True.
#Even if error != None, it should include all 3 items within the tuple: data (None), error, response (None)
return (result, None, next_response)
else:
#includeResponse==True is also not checked here.
return (result, None)
Resulting exception raised
This leads leaves the potential for a ValueError to be raised at the calling location of this function if includeResponse=True
is passed to response.next()
, as your code would be expecting a tuple of length 3 to be returned, but instead can have tuple of length 2 returned. The result is a ValueError
, as Python cannot properly unpack the returned tuple.
more_returned_data, error, response = await response.next(
includeResponse=True
)
May raise a ValueError:
while response.has_next():
logger.trace("Response from okta has next page")
more_returned_data: list[OktaObject]
> more_returned_data, error, response = await response.next(
includeResponse=True
)
E ValueError: not enough values to unpack (expected 3, got 2)
api/v1/services/okta/utils/request_helpers.py:60: ValueError
Process finished with exit code 1