Skip to content

Commit 7365589

Browse files
authored
fix(Client): clean null params from Gateway response (#83)
NOTE: Only happens when a 0 conf (proposer-proposed) txn is in queue
1 parent 96e5326 commit 7365589

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

ape_safe/client/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SafeTxID,
2525
SignatureType,
2626
UnexecutedTxData,
27+
remove_null_params,
2728
)
2829
from ape_safe.exceptions import (
2930
ActionNotPerformedError,
@@ -140,7 +141,8 @@ def get_safe_tx(self, safe_tx_hash: SafeTxID) -> Optional[SafeApiTxData]:
140141
except ClientResponseError:
141142
return None
142143

143-
return TypeAdapter(SafeApiTxData).validate_json(response.text)
144+
data = remove_null_params(response.json())
145+
return TypeAdapter(SafeApiTxData).validate_python(data)
144146

145147
def get_confirmations(self, safe_tx_hash: SafeTxID) -> Iterator[SafeTxConfirmation]:
146148
if safe_tx := self.get_safe_tx(safe_tx_hash):

ape_safe/client/types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ def clean_api_address(data: Union[AddressType, dict]) -> AddressType:
2121
return data
2222

2323

24+
def remove_null_params(data):
25+
if isinstance(data, dict):
26+
return {
27+
k: (remove_null_params(v) if isinstance(v, (dict, list, tuple)) else v)
28+
for k, v in data.items()
29+
if v is not None
30+
}
31+
32+
elif isinstance(data, list):
33+
return [
34+
remove_null_params(v) if isinstance(v, (dict, list, tuple)) else v
35+
for v in data
36+
if v is not None
37+
]
38+
39+
elif isinstance(data, tuple):
40+
return tuple(
41+
remove_null_params(v) if isinstance(v, (dict, list, tuple)) else v
42+
for v in data
43+
if v is not None
44+
)
45+
46+
else:
47+
raise ValueError("Can only supply dict, list, or tuple type")
48+
49+
2450
Address = Annotated[AddressType, BeforeValidator(clean_api_address)]
2551

2652

0 commit comments

Comments
 (0)