MikeWooster / api-client

Separate the high level client implementation from the underlying CRUD.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

paginator has no access to the original response when using JsonResponseHandler

rafalkrupinski opened this issue · comments

Describe the bug
When using both JsonResponseHandler and UrlPaginatedRequestStrategy, the next_page function receives decoded JSON body as the response param, meaning it can't read the headers

To Reproduce

def header_pagination(response: requests.Response, _: str) -> str:
    next_link = response.links.get('next')
    return None if not next_link else next_link['url']

class MyClient(apiclient.APIClient):
    def __init__(self, auth_method: apiclient.authentication_methods.BaseAuthenticationMethod):
        super().__init__(
            auth_method,
            apiclient.JsonResponseHandler,
            request_formatter=apiclient.JsonRequestFormatter,
            request_strategy=apiclient.request_strategies.UrlPaginatedRequestStrategy(header_pagination)
        )

in header_pagination, response is a dict

Expected behavior
next_page function should receive the original Response object, before decoding

Versions (please complete the following information):

  • Python version: 3.9.2
  • API Client version: 1.3.1
  • Dependency versions: requests==2.21.7, tenacity==8.0.1