Skip to content

Commit f4141a8

Browse files
authored
fix: url and path joining for cursor paginators (#695)
1 parent f976c72 commit f4141a8

File tree

3 files changed

+10
-50
lines changed

3 files changed

+10
-50
lines changed

airbyte_cdk/sources/declarative/requesters/http_requester.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ def _get_url(
168168
next_page_token=next_page_token,
169169
)
170170

171-
full_url = self._join_url(url_base, path) if url_base else url + path if path else url
171+
full_url = (
172+
self._join_url(url_base, path)
173+
if url_base
174+
else self._join_url(url, path)
175+
if path
176+
else url
177+
)
172178

173179
return full_url
174180

airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,7 @@ def path(
159159
) -> Optional[str]:
160160
token = next_page_token.get("next_page_token") if next_page_token else None
161161
if token and self.page_token_option and isinstance(self.page_token_option, RequestPath):
162-
# make additional interpolation context
163-
interpolation_context = get_interpolation_context(
164-
stream_state=stream_state,
165-
stream_slice=stream_slice,
166-
next_page_token=next_page_token,
167-
)
168-
# Replace url base to only return the path
169-
return str(token).replace(self.url_base.eval(self.config, **interpolation_context), "") # type: ignore # url_base is casted to a InterpolatedString in __post_init__
162+
return str(token)
170163
else:
171164
return None
172165

unit_tests/sources/declarative/requesters/paginators/test_default_paginator.py

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
(
3737
RequestPath(parameters={}),
3838
None,
39-
"/next_url",
39+
"https://airbyte.io/next_url",
4040
{"limit": 2},
4141
{},
4242
{},
@@ -128,7 +128,7 @@
128128
(
129129
RequestPath(parameters={}),
130130
None,
131-
"/next_url",
131+
"https://airbyte.io/next_url",
132132
{"limit": 2},
133133
{},
134134
{},
@@ -539,42 +539,3 @@ def test_path_returns_none_when_option_not_request_path() -> None:
539539
)
540540
result = paginator.path(next_page_token)
541541
assert result is None
542-
543-
544-
def test_path_with_additional_interpolation_context() -> None:
545-
page_token_option = RequestPath(parameters={})
546-
paginator = DefaultPaginator(
547-
pagination_strategy=Mock(),
548-
config={},
549-
url_base="https://api.domain.com/{{ stream_slice['campaign_id'] }}",
550-
parameters={},
551-
page_token_option=page_token_option,
552-
)
553-
# define stream_state here
554-
stream_state = {"state": "state_value"}
555-
# define stream_slice here
556-
stream_slice = StreamSlice(
557-
partition={
558-
"campaign_id": "123_abcd",
559-
},
560-
cursor_slice={
561-
"start": "A",
562-
"end": "B",
563-
},
564-
extra_fields={
565-
"extra_field_A": "value_A",
566-
"extra_field_B": "value_B",
567-
},
568-
)
569-
# define next_page_token here
570-
next_page_token = {
571-
"next_page_token": "https://api.domain.com/123_abcd/some_next_page_token_here"
572-
}
573-
574-
expected_after_interpolation = "/some_next_page_token_here"
575-
576-
assert expected_after_interpolation == paginator.path(
577-
next_page_token=next_page_token,
578-
stream_state=stream_state,
579-
stream_slice=stream_slice,
580-
)

0 commit comments

Comments
 (0)