-
Notifications
You must be signed in to change notification settings - Fork 21
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
PRO-937: Add create
and insert
table endpoints to sdk
#114
Conversation
create
and insert
table endpoints to sdk
@@ -316,40 +317,6 @@ def download_csv( | |||
), | |||
) | |||
|
|||
############################ |
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.
I think some people might still be depending on this. We might need to keep it for backwards compatibility
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.
Experience for users would not change
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! A few things I'd want changed
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.
Fantastic!
- I think we should wait by merging this until we've done PRO-1039 and PRO-1040. We are not in a hurry to get this out asap.
- In my opinion, using path as input rather than bytes is the wrong abstraction for the lowest level endpoints. The users of the library will have to read the file and provide the correct extension. We do this for
upload_csv
.
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.
Some minor questions.
schema: List[Dict[str, str]], | ||
description: str = "", | ||
is_private: bool = False, | ||
) -> Any: |
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.
Why Any
?
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.
That is what self._post
returns.
This was already implemented, but we can change that once we have something returned
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.
If so, should this change now? 😄
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.
I am trying to say that Any
is not a useful return type. What should users expect back when calling the create_table
or insert_table
functions ?
but we can change that once we have something returned
But we should already have a response returned from the API, right ?
That is what self._post returns.
The fact that self._post
returns Any
, might have been a bad design / tech debt. If this is part of the public API, which we cannot change, maybe we can consider returning a more useful type here.
If not an easy change, let's keep it like that.
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.
I agree that it was probably not the best decision.
This function is kind of unnecessary, which is used to handle _post
, _get
, and _patch
responses
dune-client/dune_client/api/base.py
Lines 139 to 150 in e3f6c98
def _handle_response(self, response: Response) -> Any: | |
"""Generic response handler utilized by all Dune API routes""" | |
try: | |
# Some responses can be decoded and converted to DuneErrors | |
response_json = response.json() | |
self.logger.debug(f"received response {response_json}") | |
return response_json | |
except JSONDecodeError as err: | |
# Others can't. Only raise HTTP error for not decodable errors | |
response.raise_for_status() | |
raise ValueError("Unreachable since previous line raises") from err | |
Should have just returned the Response
object.
response.json()
returns Any
, so this will take a bit of work.
And as such, I don't think is worth it.
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.
This was already implemented, but we can change that once we have something returned
I take this back, this was not as simple as I thought it would be.
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.
Thanks 🖖
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.
Sorry folks, this was my fault
dune-client/dune_client/api/execution.py
Lines 66 to 72 in b9db190
def get_execution_status(self, job_id: str) -> ExecutionStatusResponse: | |
"""GET status from Dune API for `job_id` (aka `execution_id`)""" | |
response_json = self._get(route=f"/execution/{job_id}/status") | |
try: | |
return ExecutionStatusResponse.from_dict(response_json) | |
except KeyError as err: | |
raise DuneError(response_json, "ExecutionStatusResponse", err) from err |
Here would have been the same thing. Since I am currently implementing these API routes in the Node project, I will submit a corresponding PR for this one.
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.
Here is the related PR: #117
dune_client/api/base.py
Outdated
headers: Dict[str, str] = {}, | ||
) -> Any: | ||
# pylint: disable=dangerous-default-value |
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.
Mutable default arguments is indeed dangerous in Python. So please remove the pylint thing and change: This will only be initialized once, and any changes to it will be durable. See https://docs.python-guide.org/writing/gotchas/
So we need to change it to Optional[Dict[str, str]] = None
and then handle it in the body of the method
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.
This was done in response to this.
#114 (comment)
But I can change it back
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.
Please do!
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.
Done!
schema: List[Dict[str, str]], | ||
description: str = "", | ||
is_private: bool = False, | ||
) -> Any: |
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.
If so, should this change now? 😄
self, | ||
namespace: str, | ||
table_name: str, | ||
schema: List[Dict[str, str]], |
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.
At some point we probably want to create an enum of the possible types, but not yet!
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.
Do you happen to have a list of all the possible types?
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.
Yup they're defined here
https://dune-tables-docs.mintlify.app/api-reference/tables/endpoint/create
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.
Great!
Sorry dismissing to unblock PR merge
class TableAPI(BaseRouter): | ||
""" | ||
Implementation of Table endpoints - Plus subscription only | ||
https://docs.dune.com/api-reference/tables/ |
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.
Note: There is no landing page for the Tables API. This url redirects to https://docs.dune.com/api-reference/tables/endpoint/create and there only appears to be one direct link in the docs page (inside a comment on uploadCSV)
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.
Hmm, you are correct.
Opening a ticket internally
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.
Great callout! It should probably be an "Overview" or similar like with the other endpoint groups.
Hey @waddahAldrobi I am loving all these great contributions, but do you think you could "Squash Merge" your PRs so that the commit history on main is easier to navigate? This is difficult to follow and contains a lot of irrelevant stuff. |
@bh2smith 💯 that would have been a much better idea 👍 |
In this PR, we add support for the new
table
endpoints in the SDK:We move the
upload_csv
function with the new endpoints intoapi/table.py
to consolidate all table endpoints in one file