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

docs(rest_client): note about data_selector #2101

Merged
merged 2 commits into from
Nov 28, 2024
Merged

Conversation

joscha
Copy link
Contributor

@joscha joscha commented Nov 27, 2024

I personally think it's a bug and

if self.data_selector:
    return self.extract_response(response, self.data_selector)

should be called automatically for all requests (.get(...).json(), ...) when given (1), however it would be a breaking change, so updating the documentation is the next best thing.
Might also be possibly worth deprecating the parameter from the global RESTClient constructor, given the fact that it is only used inside .paginate(...) (2).

Let me know if you want me to open a pull request for (1) and/or (2) instead of this one.

Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit 343dc8d
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/674867165286830008667df7

@burnash
Copy link
Collaborator

burnash commented Nov 27, 2024

Hey @joscha you're absolutely right. I'd say it should not be in RESTClient.__init__ indeed. I would opt for (2) as I don't think it's really needed for get() since the data (if it's a JSON response) can be retrieved directly from the resulted object.
Thanks for spotting this!

@joscha
Copy link
Contributor Author

joscha commented Nov 27, 2024

Do you want me to remove it from Rest client? It is a breaking change, albeit a super easy fix. Alternatively I could deprecate it instead and leave the comment in this PR.

@burnash
Copy link
Collaborator

burnash commented Nov 27, 2024

Do you want me to remove it from Rest client? It is a breaking change, albeit a super easy fix. Alternatively I could deprecate it instead and leave the comment in this PR.

Let's deprecate it now (with the DeprecationWarning) and we'll remove it with the next major release.

@joscha
Copy link
Contributor Author

joscha commented Nov 27, 2024

Do you want me to remove it from Rest client? It is a breaking change, albeit a super easy fix. Alternatively I could deprecate it instead and leave the comment in this PR.

Let's deprecate it now (with the DeprecationWarning) and we'll remove it with the next major release.

Okay. Will update the PR.

@joscha
Copy link
Contributor Author

joscha commented Nov 28, 2024

Whilst doing the update I just realized that this was probably introduced for convenience. Like for example an API with lots of paginated endpoints that all follow the same pattern. It allows to do something like:

rest_client = RESTClient(..., data_selector="data")

yield from rest_client.paginate("a")
yield from rest_client.paginate("b")
yield from rest_client.paginate("c")
...
yield from rest_client.paginate("x")

without having to pass the data_selector="data" to each of them:

rest_client = RESTClient(...)

yield from rest_client.paginate("a", data_selector="data")
yield from rest_client.paginate("b", data_selector="data")
yield from rest_client.paginate("c", data_selector="data")
...
yield from rest_client.paginate("x", data_selector="data")

Which is definitely more brittle and less DRY.
Whilst it being a bit confusing to not be respected in get/... I actually do think after looking at the code, that there's validity in this convenience, so I'd propose to not deprecate it but leave the comment as-is. WDYT @burnash?

@burnash
Copy link
Collaborator

burnash commented Nov 28, 2024

I actually do think after looking at the code, that there's validity in this convenience, so I'd propose to not deprecate it but leave the comment as-is.

Yes, also makes sense. Let's do that. I have a suggestion to adjust the wording though.

@joscha joscha requested a review from burnash November 28, 2024 12:51
Copy link
Collaborator

@burnash burnash left a comment

Choose a reason for hiding this comment

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

Thank you, @joscha!

@burnash burnash merged commit eefe77b into dlt-hub:devel Nov 28, 2024
52 of 58 checks passed
@joscha joscha deleted the patch-1 branch November 28, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants