Skip to content

Commit

Permalink
Fix Pending Bug. (#23)
Browse files Browse the repository at this point in the history
As a temporary solution to #22 (although the field is not intended to be optional) we make the missing field from response optional.
  • Loading branch information
bh2smith authored Oct 7, 2022
1 parent 2d4ceaa commit 93afe3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
20 changes: 8 additions & 12 deletions dune_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,21 @@ class ResultMetadata:
result_set_bytes: int
total_row_count: int
datapoint_count: int
pending_time_millis: int
pending_time_millis: Optional[int]
execution_time_millis: int

@classmethod
def from_dict(cls, data: dict[str, int | list[str]]) -> ResultMetadata:
def from_dict(cls, data: dict[str, Any]) -> ResultMetadata:
"""Constructor from dictionary. See unit test for sample input."""
assert isinstance(data["column_names"], list)
assert isinstance(data["result_set_bytes"], int)
assert isinstance(data["total_row_count"], int)
assert isinstance(data["datapoint_count"], int)
assert isinstance(data["pending_time_millis"], int)
assert isinstance(data["execution_time_millis"], int)
pending_time = data.get("pending_time_millis", None)
return cls(
column_names=data["column_names"],
result_set_bytes=data["result_set_bytes"],
total_row_count=data["total_row_count"],
datapoint_count=data["datapoint_count"],
pending_time_millis=data["pending_time_millis"],
execution_time_millis=data["execution_time_millis"],
result_set_bytes=int(data["result_set_bytes"]),
total_row_count=int(data["total_row_count"]),
datapoint_count=int(data["datapoint_count"]),
pending_time_millis=int(pending_time) if pending_time else None,
execution_time_millis=int(data["execution_time_millis"]),
)


Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TimeData,
ExecutionResult,
ResultMetadata,
DuneError,
)


Expand Down Expand Up @@ -115,6 +116,29 @@ def test_parse_status_response(self):
expected, ExecutionStatusResponse.from_dict(self.status_response_data)
)

def test_parse_known_status_response(self):
# For context: https://github.com/cowprotocol/dune-client/issues/22
response = {
"execution_id": "01GES18035K5C4GDTY12Q79GBD",
"query_id": 1317323,
"state": "QUERY_STATE_COMPLETED",
"submitted_at": "2022-10-07T10:53:18.822127Z",
"expires_at": "2024-10-06T10:53:20.729373Z",
"execution_started_at": "2022-10-07T10:53:18.823105936Z",
"execution_ended_at": "2022-10-07T10:53:20.729372559Z",
"result_metadata": {
"column_names": ["token"],
"result_set_bytes": 815,
"total_row_count": 18,
"datapoint_count": 18,
"execution_time_millis": 1906,
},
}
try:
ExecutionStatusResponse.from_dict(response)
except DuneError as err:
self.fail(f"Unexpected error {err}")

def test_parse_status_response_completed(self):
self.assertEqual(
ExecutionStatusResponse(
Expand Down

0 comments on commit 93afe3b

Please sign in to comment.