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

Handle insert_table errors #129

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dune_client/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dune_client.models import (
DuneError,
InsertTableResult,
InsertTableErrorResult,
CreateTableResult,
DeleteTableResult,
)
Expand Down Expand Up @@ -88,7 +89,7 @@ def insert_table(
table_name: str,
data: IO[bytes],
content_type: str,
) -> InsertTableResult:
) -> InsertTableResult | InsertTableErrorResult:
"""
https://docs.dune.com/api-reference/tables/endpoint/insert
The insert table endpoint allows you to insert data into an existing table in Dune.
Expand All @@ -103,7 +104,11 @@ def insert_table(
headers={"Content-Type": content_type},
data=data,
)
return InsertTableResult.from_dict(result_json)
if "error" in result_json:
return InsertTableErrorResult.from_dict(result_json)
else:
return InsertTableResult.from_dict(result_json)


def delete_table(self, namespace: str, table_name: str) -> DeleteTableResult:
"""
Expand Down
9 changes: 9 additions & 0 deletions dune_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ class InsertTableResult(DataClassJsonMixin):
"""

rows_written: int
bytes_written: int

@dataclass
class InsertTableErrorResult(DataClassJsonMixin):
"""
Data type returned by table/insert operation error
"""

error: str


@dataclass
Expand Down
Loading