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

RESTClient: add PageNumberPaginator #1307

Merged
merged 10 commits into from
May 7, 2024

Conversation

burnash
Copy link
Collaborator

@burnash burnash commented May 1, 2024

Implements #1205

This PR also extracts the common code from the OffsetPaginator into BaseNumericPaginator.

@burnash burnash self-assigned this May 1, 2024
Copy link

netlify bot commented May 1, 2024

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit 5dfb678
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/663a4af6542b7c00082d7e3d

@burnash burnash requested a review from rudolfix May 1, 2024 16:52
@burnash burnash added the sprint Marks group of tasks with core team focus at this moment label May 1, 2024
@@ -64,7 +64,133 @@ def update_request(self, request: Request) -> None:
return


class OffsetPaginator(BasePaginator):
class BaseNumericPaginator(BasePaginator):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rudolfix, not sure if the name should be "Base*", this class could be useful on its own. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe Simple* is better for tbh both look fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

heh I spent 10 minutes thinking about good name :) maybe RangePaginator? because it looks like python range

@burnash burnash requested review from sultaniman and sh-rp May 2, 2024 15:59
sultaniman
sultaniman previously approved these changes May 3, 2024
Copy link
Contributor

@sultaniman sultaniman left a comment

Choose a reason for hiding this comment

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

Maybe tests should parametrized because there two groups of similar tests

@@ -64,7 +64,133 @@ def update_request(self, request: Request) -> None:
return


class OffsetPaginator(BasePaginator):
class BaseNumericPaginator(BasePaginator):
Copy link
Collaborator

Choose a reason for hiding this comment

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

heh I spent 10 minutes thinking about good name :) maybe RangePaginator? because it looks like python range

self,
param_name: str,
initial_value: int,
total_path: jsonpath.TJsonPath,
Copy link
Collaborator

Choose a reason for hiding this comment

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

When writing a paginator for moviesdb some endpoints had a regular page number paginator, but others were a top list endpoints where the total was a huge number which could not be reached, so I did this
https://github.com/dlt-hub/dlt-rest-client-hackathon/blob/main/moviesdb/page_number_paginator.py#L17

Where I could put a maximum value on total, with maximum value the total is optional. does it make sense to add it? IMO those broken paginators are quite common.

in that case we could thing about base class as a real range(start, stop, step)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rudolfix thanks for suggestion. I think it could be very useful to control the pagination.
I've implemented the maximum_value in the f7f7860.
I also really like the idea of making maximum_value a substitute for total number – this way we make this paginator very versatile. Will send the update soon.

self._has_next_page = False

def _handle_missing_total(self, response_json: Dict[str, Any]) -> None:
raise ValueError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is good! thx! I'll probably create specialized exceptions for pagintors in #1281

@burnash
Copy link
Collaborator Author

burnash commented May 3, 2024

Maybe tests should parametrized because there two groups of similar tests

@sultaniman which two groups do you mean? TestOffsetPaginator & TestPageNumberPaginator?

@burnash burnash requested a review from rudolfix May 6, 2024 14:35
@burnash burnash removed the sprint Marks group of tasks with core team focus at this moment label May 6, 2024
Copy link
Collaborator

@rudolfix rudolfix left a comment

Choose a reason for hiding this comment

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

take a look at the comments, you can fix them and merge. the code overall is good.

what worries me is that we do not do any end to end tests for paginators. why not to extend mock server and check them out?

maybe you could create a ticket for that and @sultaniman / you / me can implement it later :)

self.limit_param = limit_param
self.total_path = jsonpath.compile_path(total_path)
if initial_limit is not None:
warnings.warn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have really good system for deprecations, look for DltDeprecationWarning not only does this but also shows usage of such functions in mypy and VSCode :)

@rudolfix
Copy link
Collaborator

rudolfix commented May 6, 2024

@burnash btw. docstrings are PRO

@sultaniman
Copy link
Contributor

@rudolfix sure I will create a note for myself to improve testing then.

sultaniman
sultaniman previously approved these changes May 7, 2024
@burnash burnash force-pushed the feat/rest_client_pagenumberpaginator branch from efd9070 to 5dfb678 Compare May 7, 2024 15:38
@burnash burnash merged commit 8ed879a into devel May 7, 2024
47 of 50 checks passed
@burnash burnash deleted the feat/rest_client_pagenumberpaginator branch May 7, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants