Skip to content

Commit

Permalink
Dune Error on failed Create Table (#147)
Browse files Browse the repository at this point in the history
This is more consistent with the other routes as well.
  • Loading branch information
bh2smith authored Jan 13, 2025
1 parent bd4594e commit cf2bb50
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 7 additions & 4 deletions dune_client/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def create_table(
"is_private": is_private,
},
)
return CreateTableResult.from_dict(result_json)
try:
return CreateTableResult.from_dict(result_json)
except KeyError as err:
raise DuneError(result_json, "CreateTableResult", err) from err

def insert_table(
self,
Expand All @@ -107,7 +110,7 @@ def insert_table(
try:
return InsertTableResult.from_dict(result_json)
except KeyError as err:
raise DuneError(result_json, "InsertTable", err) from err
raise DuneError(result_json, "InsertTableResult", err) from err

def clear_data(self, namespace: str, table_name: str) -> ClearTableResult:
"""
Expand All @@ -120,7 +123,7 @@ def clear_data(self, namespace: str, table_name: str) -> ClearTableResult:
try:
return ClearTableResult.from_dict(result_json)
except KeyError as err:
raise DuneError(result_json, "ClearData", err) from err
raise DuneError(result_json, "ClearTableResult", err) from err

def delete_table(self, namespace: str, table_name: str) -> DeleteTableResult:
"""
Expand All @@ -132,4 +135,4 @@ def delete_table(self, namespace: str, table_name: str) -> DeleteTableResult:
try:
return DeleteTableResult.from_dict(response_json)
except KeyError as err:
raise DuneError(response_json, "DeleteTable", err) from err
raise DuneError(response_json, "DeleteTableResult", err) from err
19 changes: 18 additions & 1 deletion tests/e2e/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_create_table_success(self):
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)

namespace = "test"
namespace = "bh2smith"
table_name = "dataset_e2e_test"

self.assertEqual(
Expand All @@ -270,6 +270,23 @@ def test_create_table_success(self):
),
)

# @unittest.skip("Requires custom namespace and table_name input.")
def test_create_table_error(self):
client = DuneClient("Invalid Key")

namespace = "test"
table_name = "table"
with self.assertRaises(DuneError) as err:
client.create_table(
namespace=namespace,
table_name=table_name,
description="",
schema=[
{"name": "ALL_CAPS", "type": "timestamp"},
],
is_private=False,
)

@unittest.skip("Requires custom namespace and table_name input.")
def test_insert_table_csv_success(self):
# Make sure the table already exists and csv matches table schema.
Expand Down

0 comments on commit cf2bb50

Please sign in to comment.