From cf2bb506c450c7e3eab41363cbf5c3a650e055b9 Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Mon, 13 Jan 2025 10:19:13 +0100 Subject: [PATCH] Dune Error on failed Create Table (#147) This is more consistent with the other routes as well. --- dune_client/api/table.py | 11 +++++++---- tests/e2e/test_client.py | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/dune_client/api/table.py b/dune_client/api/table.py index c8d4762..04da7c6 100644 --- a/dune_client/api/table.py +++ b/dune_client/api/table.py @@ -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, @@ -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: """ @@ -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: """ @@ -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 diff --git a/tests/e2e/test_client.py b/tests/e2e/test_client.py index ed4b41a..6b7af1e 100644 --- a/tests/e2e/test_client.py +++ b/tests/e2e/test_client.py @@ -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( @@ -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.