-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
airbyte-cdk offset pagination strategy: page_size to be interpolated … #19646
airbyte-cdk offset pagination strategy: page_size to be interpolated … #19646
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roman-yermilov-gl could you indicate why you're making this change, include a snippet of how this changes the input YAML, and add tests that prove the new functionality works? It's hard to give useful feedback on a PR without that information :)
Thanks for comments. I updated description and made fixes in tests |
...yte-cdk/python/unit_tests/sources/declarative/requesters/paginators/test_offset_increment.py
Show resolved
Hide resolved
.../python/airbyte_cdk/sources/declarative/requesters/paginators/strategies/offset_increment.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
# InterpolatedString page_size may contain one of int/str types, | ||
# so we need to ensure that its `.string` attribute is of *string* type | ||
self.page_size.string = str(self.page_size.string) | ||
self.page_size = self.page_size.eval(self.config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When possible, we try to perform the interpolation evluation eval()
at runtime instead of parse time in post_init
. So in this case, self.page_size would be the interpolated string (as you mentioned above) but we should move evaluation of it into the get_page_size()
.
Now that this could be an interpolated string or just a normal string, the type hints in the getter method get_page_size() -> Optional[int]
is now a bit misleading. I think we should also add some error handling in the event that this does not evaluate into an integer since it won't behave correctly when get_page_size()
gets invoked by parent classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! just one comment about reusing some code
|
||
def next_page_token(self, response: requests.Response, last_records: List[Mapping[str, Any]]) -> Optional[Any]: | ||
if len(last_records) < self.page_size: | ||
if len(last_records) < self.page_size.eval(self.config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of calling self.page_size.eval(self.config)
we can replace this with self.get_page_size()
so that we can reuse the method without needing to duplicate the type check
155eaef
to
45adef5
Compare
…of how to use OffsetIncrement strategy
gentle reminder to run |
It is often happen that
page_size
need to be specified per stream. With current changes we can set thepage_size
in stream options while define it only once: