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: Workflow execution decimal cannot be serialized #2372

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow execution decimal cannot be serialized

@@ -140,6 +141,8 @@ def default(self, obj):
return str(obj)
if isinstance(obj, datetime.datetime):
return obj.strftime("%Y-%m-%d %H:%M:%S")
if isinstance(obj, decimal.Decimal):
return float(obj)
else:
return json.JSONEncoder.default(self, obj)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No significant issues were found in the provided code. However, there is a minor suggestion for improvement:

+        if isinstance(obj, decimal.Decimal):
+# Use float() to convert Decimal instead of str()
+            return float(obj)

This change ensures that when decimal.Decimal objects are encountered during serialization, they are converted to a floating-point number rather than converting them to strings. This might be more suitable depending on how you want to store or manipulate these numbers later in your application.

@shaohuzhang1 shaohuzhang1 merged commit fa1886a into main Feb 24, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_decimal branch February 24, 2025 08:30
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.

1 participant