Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[low code connectors] fix bug where headers were not passed to cursor interpolation #15347

Merged

Conversation

brianjlai
Copy link
Contributor

What

We were not correctly passing headers to the cursor value so when we tried to perform interpolation to get values from headers it would fail.

How

Pass the headers to interpolation like we do for the stop condition. I also added a little bit of code to make it easier to extract next urls in an indexable way. The existing implementation on requests.Response returns a giant string of links which would be a pain for developers to extract. Relying on the existing Response.links() helper method and storing it back onto the response is much more user friendly. +tests

Recommended reading order

  1. cursor_pagination_strategy.py

@brianjlai brianjlai requested review from girarda and sherifnada August 5, 2022 05:04
@brianjlai brianjlai requested a review from a team as a code owner August 5, 2022 05:04
@github-actions github-actions bot added the CDK Connector Development Kit label Aug 5, 2022
Copy link
Contributor

@girarda girarda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! Where do you think we should document this behavior?

@sherifnada
Copy link
Contributor

Can you clarify how adding the pre-parsed headers field changes the interface for the developer? What’s the before and after?

@brianjlai
Copy link
Contributor Author

Before:
headers.linkreturns a single string of all the links. For Greenhouse for example:

"<https://harvest.greenhouse.io/v1/applications?page=2&per_page=1>; rel="next",<https://harvest.greenhouse.io/v1/applications?page=8&per_page=1>; rel="last""

This is probably impossible for developers to parse without utility functions added in jinja for string manpulation and regexes. Basically they would need to replicate all the behavior of requests.Response.links() property method in their interpolated method.

After:
headers.linkretains a dictionary of urls indexed by keys. Usually next or last

YAML config:
cursor_value: "{{ headers.link.next.url }}"

@brianjlai
Copy link
Contributor Author

@girarda
Thats a good question. I feel like maybe the best spot is to add a recipe to the cookbook saying that this is how you would perform cursor pagination when an API stores the next URL to paginate on in the headers. The response next url is probably more common but I bet more than just greenhouse does this type of thing

@sherifnada
Copy link
Contributor

the best spot
would also recommend adding it to the different components inside a retriever e.g: paginators etc since that would be where a user consumes it.

@brianjlai
Copy link
Contributor Author

@sherifnada that's a good point. Although I don't think the other pagination strategies need or use the response for anything. One area that I do think could get some value from receiving headers is in our error handlers. We do this for some error handling strategies, but I do think there is one scenario not covered in http_response_filter() where headers might be useful, I'll update to cover that as well.

@brianjlai brianjlai merged commit 054cbbe into master Aug 8, 2022
@brianjlai brianjlai deleted the brian/fix_headers_not_passed_to_pagination_strategy branch August 8, 2022 19:23
@@ -56,7 +56,7 @@ def matches(self, response: requests.Response) -> Optional[ResponseAction]:
return None

def _response_matches_predicate(self, response: requests.Response) -> bool:
return self.predicate and self.predicate.eval(None, response=response.json())
return self.predicate and self.predicate.eval(None, response=response.json(), headers=response.headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update the "link" header here to be consistent with the cursor pagination strategy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants