Skip to content

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

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ def __init__(
def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Any]:
decoded_response = self._decoder.decode(response)
headers = response.headers

# The default way that link is presented in requests.Response is a string of various links (last, next, etc). This
# is not indexable or useful for parsing the cursor, so we replace it with the link dictionary from response.links
headers["link"] = response.links
if self._stop_condition:
should_stop = self._stop_condition.eval(self._config, response=decoded_response, headers=headers, last_records=last_records)
if should_stop:
return None
token = self._cursor_value.eval(config=self._config, last_records=last_records, response=decoded_response)
token = self._cursor_value.eval(config=self._config, last_records=last_records, response=decoded_response, headers=headers)
return token if token else None
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
("test_token_not_found", "{{ response.invalid_key }}", None, None),
("test_static_token_with_stop_condition_false", "token", InterpolatedBoolean("{{False}}"), "token"),
("test_static_token_with_stop_condition_true", "token", InterpolatedBoolean("{{True}}"), None),
("test_token_from_header", "{{ headers.next }}", InterpolatedBoolean("{{ not headers.has_more }}"), "ready_to_go"),
(
"test_token_from_response_header_links",
"{{ headers.link.next.url }}",
InterpolatedBoolean("{{ not headers.link.next.url }}"),
"https://adventure.io/api/v1/records?page=2&per_page=100",
),
],
)
def test_cursor_pagination_strategy(test_name, template_string, stop_condition, expected_token):
Expand All @@ -29,7 +36,8 @@ def test_cursor_pagination_strategy(test_name, template_string, stop_condition,
strategy = CursorPaginationStrategy(template_string, config, stop_condition, decoder)

response = requests.Response()
response.headers = {"has_more": True}
link_str = '<https://adventure.io/api/v1/records?page=2&per_page=100>; rel="next"'
response.headers = {"has_more": True, "next": "ready_to_go", "link": link_str}
response_body = {"_metadata": {"content": "content_value"}, "accounts": [], "end": 99, "total": 200, "characters": {}}
response._content = json.dumps(response_body).encode("utf-8")
last_records = [{"id": 0, "more_records": True}, {"id": 1, "more_records": True}]
Expand Down