Skip to content

Commit bfd6811

Browse files
fix: add default value for CreateTableResult.already_existed field (#160)
1 parent 1d466e8 commit bfd6811

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

dune_client/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ class CreateTableResult(DataClassJsonMixin):
369369
table_name: str
370370
full_name: str
371371
example_query: str
372-
already_existed: bool
373372
message: str
373+
# kept for backward compatibility, always False, unreliable
374+
already_existed: Optional[bool] = False
374375

375376

376377
@dataclass

tests/e2e/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ def test_create_table_success(self):
248248

249249
namespace = "bh2smith"
250250
table_name = "dataset_e2e_test"
251-
252251
self.assertEqual(
253252
client.create_table(
254253
namespace=namespace,
@@ -266,6 +265,7 @@ def test_create_table_success(self):
266265
"table_name": table_name,
267266
"full_name": f"dune.{namespace}.{table_name}",
268267
"example_query": f"select * from dune.{namespace}.{table_name} limit 10",
268+
"message": "Table created successfully",
269269
}
270270
),
271271
)
@@ -357,7 +357,7 @@ def test_delete_table_success(self):
357357
),
358358
DeleteTableResult.from_dict(
359359
{
360-
"message": "Table teamwaddah.waddah_test3 successfully deleted",
360+
"message": f"Table {namespace}.{table_name} successfully deleted",
361361
}
362362
),
363363
)

tests/unit/test_models.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ExecutionResult,
1818
ResultMetadata,
1919
DuneError,
20+
CreateTableResult,
2021
)
2122
from dune_client.types import QueryParameter
2223
from dune_client.query import DuneQuery, QueryMeta, QueryBase
@@ -279,6 +280,33 @@ def test_dune_query_from_dict(self):
279280
)
280281
self.assertEqual(expected, DuneQuery.from_dict(json.loads(example_response)))
281282

283+
def test_create_table_result_with_already_existed_field(self):
284+
"""Test CreateTableResult parsing when API response includes already_existed field"""
285+
response_data = {
286+
"namespace": "test_namespace",
287+
"table_name": "test_table",
288+
"full_name": "dune.test_namespace.test_table",
289+
"example_query": "select * from dune.test_namespace.test_table limit 10",
290+
"already_existed": False,
291+
"message": "Table created successfully",
292+
}
293+
result = CreateTableResult.from_dict(response_data)
294+
self.assertFalse(result.already_existed)
295+
296+
def test_create_table_result_missing_already_existed_field(self):
297+
"""Test CreateTableResult parsing when API response lacks already_existed field (verify default value)"""
298+
response_data = {
299+
"namespace": "test_namespace",
300+
"table_name": "test_table",
301+
"full_name": "dune.test_namespace.test_table",
302+
"example_query": "select * from dune.test_namespace.test_table limit 10",
303+
"message": "Table created successfully",
304+
# Note: intentionally omitting already_existed field
305+
}
306+
result = CreateTableResult.from_dict(response_data)
307+
# Verify default value is False
308+
self.assertFalse(result.already_existed)
309+
282310

283311
if __name__ == "__main__":
284312
unittest.main()

0 commit comments

Comments
 (0)