Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix datetime json serialization #123

Merged
merged 1 commit into from
Apr 20, 2022

Conversation

DusanFedorcak
Copy link
Contributor

I stumbled upon another serialization error. This

from terra_sdk.client.lcd import LCDClient
from terra_sdk.util.hash import hash_amino

terra = LCDClient(chain_id="columbus-5", url="https://lcd.terra.dev")
bi = terra.tendermint.block_info(7309740)
info = terra.tx.tx_info(hash_amino(bi["block"]["data"]["txs"][143]))
info.tx.body.messages[0].to_json()

raises

TypeError: Object of type datetime is not JSON serializable
at terra_sdk/util/json.py:58

The fix is below but I'm not sure about the general solution (turning a datetime into a str as to_data seems to be used on many places)

Also, I believe that the terra_sdk.util.converter.to_isoformat() has a small bug
I was not able to parse it back with dateutils unlet the "dot" is removed:

dateutil.parser.isoparse(json.loads(info.tx.body.messages[0].to_json())["allowance"]["expiration"])

@Vritra4 Vritra4 merged commit 1fec37d into terra-money:main Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants