duneanalytics / dune-client

A framework for interacting with Dune Analytics' officially supported API service
Apache License 2.0
91 stars 21 forks source link

`create_table()` should give better error for bad schema argument #140

Open et-dynamic opened 2 weeks ago

et-dynamic commented 2 weeks ago

I stumbled upon this when providing a column name in all caps, but it seems to happen when you provide any bad schema.

good_schema = [{"name": "colname", "type": "varchar"}]
all_caps_colname_schema = [{"name": "COLNAME", "type": "varchar"}]
empty_schema = [{}]

# creates table successfully
dune.create_table(
    namespace = namespace,
    table_name = table_name + "_good",
    schema = good_schema
)

# does not create a table, and does not tell me that the all-caps column name is an issue
dune.create_table(
    namespace = namespace,
    table_name = table_name + "_all_caps",
    schema = all_caps_colname_schema
)

# ditto - same error
dune.create_table(
    namespace = namespace,
    table_name = table_name + "_empty_schema",
    schema = empty_schema
)

Here's the stack trace which is the same for the last 2 cases:

Traceback (most recent call last):
  File "~/path/to/create_table_bug.py", line 21, in <module>
    dune.create_table(
  File "~/dune-pipeline-env/lib/python3.12/site-packages/dune_client/api/table.py", line 83, in create_table
    return CreateTableResult.from_dict(result_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/dune-pipeline-env/lib/python3.12/site-packages/dataclasses_json/api.py", line 70, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/dune-pipeline-env/lib/python3.12/site-packages/dataclasses_json/core.py", line 185, in _decode_dataclass
    field_value = kvs[field.name]
                  ~~~^^^^^^^^^^^^
KeyError: 'example_query'
bh2smith commented 2 weeks ago

Ya that's definitely an unusual error. Is this something you'd like to take a stab at fixing?