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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/application/models/application.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
@desc:
"""
import datetime
import decimal
import json
import uuid

@@ -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.