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

PRO-937: Add create and insert table endpoints to sdk #114

Merged
merged 16 commits into from
Mar 19, 2024

Conversation

waddahAldrobi
Copy link
Contributor

@waddahAldrobi waddahAldrobi commented Mar 15, 2024

In this PR, we add support for the new table endpoints in the SDK:

We move the upload_csv function with the new endpoints into api/table.py to consolidate all table endpoints in one file

@waddahAldrobi waddahAldrobi changed the title [WIP] Pro 937 add table endpoints to sdk Pro 937 add table endpoints to sdk Mar 18, 2024
@waddahAldrobi waddahAldrobi requested review from a team and hawkaa March 18, 2024 11:46
@waddahAldrobi waddahAldrobi changed the title Pro 937 add table endpoints to sdk PRO-937: Add create and insert table endpoints to sdk Mar 18, 2024
@waddahAldrobi waddahAldrobi marked this pull request as ready for review March 18, 2024 11:46
@@ -316,40 +317,6 @@ def download_csv(
),
)

############################
Copy link

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

Copy link
Contributor Author

@waddahAldrobi waddahAldrobi Mar 18, 2024

Choose a reason for hiding this comment

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

dune_client/api/table.py Outdated Show resolved Hide resolved
Copy link
Member

@vegarsti vegarsti left a 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

dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
hawkaa
hawkaa previously requested changes Mar 18, 2024
Copy link
Contributor

@hawkaa hawkaa left a comment

Choose a reason for hiding this comment

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

Fantastic!

  1. 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.
  2. 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.

dune_client/api/base.py Outdated Show resolved Hide resolved
dune_client/api/base.py Show resolved Hide resolved
dune_client/api/extensions.py Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
dune_client/api/table.py Outdated Show resolved Hide resolved
Copy link

@helanto helanto left a comment

Choose a reason for hiding this comment

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

Some minor questions.

dune_client/api/base.py Show resolved Hide resolved
tests/e2e/test_client.py Show resolved Hide resolved
schema: List[Dict[str, str]],
description: str = "",
is_private: bool = False,
) -> Any:
Copy link

Choose a reason for hiding this comment

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

Why Any ?

Copy link
Contributor Author

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

Copy link
Member

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? 😄

Copy link

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.

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.

Copy link

Choose a reason for hiding this comment

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

Thanks 🖖

Copy link
Collaborator

@bh2smith bh2smith Mar 25, 2024

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 ☹️ . But these internal private methods return Any and the idea is to convert them to the expected type inside these pubic facing interfaces. So, for example... we have these Object.from_dict() methods that convert Any responses to the expected types:

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.

Copy link
Collaborator

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

tests/e2e/test_client.py Outdated Show resolved Hide resolved
Comment on lines 187 to 189
headers: Dict[str, str] = {},
) -> Any:
# pylint: disable=dangerous-default-value
Copy link
Member

@vegarsti vegarsti Mar 19, 2024

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

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Please do!

Copy link
Contributor Author

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:
Copy link
Member

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? 😄

dune_client/api/table.py Outdated Show resolved Hide resolved
self,
namespace: str,
table_name: str,
schema: List[Dict[str, str]],
Copy link
Member

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!

Copy link
Collaborator

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?

Copy link
Contributor Author

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

(Link is in docstring)
image

Copy link
Member

@vegarsti vegarsti left a comment

Choose a reason for hiding this comment

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

Great!

@waddahAldrobi waddahAldrobi dismissed hawkaa’s stale review March 19, 2024 12:19

Sorry dismissing to unblock PR merge

@waddahAldrobi waddahAldrobi merged commit 1cbe59c into main Mar 19, 2024
3 checks passed
class TableAPI(BaseRouter):
"""
Implementation of Table endpoints - Plus subscription only
https://docs.dune.com/api-reference/tables/
Copy link
Collaborator

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)

image

Copy link
Contributor Author

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

Copy link
Contributor

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.

@bh2smith bh2smith deleted the PRO-937-add-table-endpoints-to-sdk branch March 25, 2024 09:51
@bh2smith
Copy link
Collaborator

bh2smith commented Mar 25, 2024

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.
Screenshot 2024-03-25 at 12 32 05

@waddahAldrobi
Copy link
Contributor Author

but do you think you could "Squash Merge" your PRs so that the commit history on main is easier to navigate?

@bh2smith 💯 that would have been a much better idea 👍

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.

6 participants