Skip to content
New issue

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

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

Already on GitHub? # to your account

Review marshalling of Decimal values #52

Open
amotl opened this issue Oct 31, 2024 · 0 comments
Open

Review marshalling of Decimal values #52

amotl opened this issue Oct 31, 2024 · 0 comments

Comments

@amotl
Copy link
Contributor

amotl commented Oct 31, 2024

About

Based on a comment by @seut,

I think using a float won't work as a Decimal has a 128bit range and thus cannot fit into a float.

this piece of code may want to be reviewed.

def patch_json_encoder():
"""
`Decimal` types have been rendered as strings.
TODO: Upstream to crate-python.
"""
json_encoder_default = CrateJsonEncoder.default
def default(self, o):
if isinstance(o, Decimal):
return float(o)
return json_encoder_default(o)
CrateJsonEncoder.default = default

References

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant