Skip to content

fix(python): missing Decimal to float conversion for body serializer #4618

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

Merged
merged 1 commit into from
Mar 21, 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from decimal import Decimal
from json import dumps
from typing import Any, Dict, Optional
from urllib.parse import urlencode
Expand Down Expand Up @@ -42,6 +43,7 @@ def body_serializer(obj: Any) -> Any:

If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is Decimal, convert to float and return.
If obj is list, sanitize each element in the list.
If obj is dict, return the dict.
If obj is OpenAPI model, return the properties dict.
Expand All @@ -54,6 +56,8 @@ def body_serializer(obj: Any) -> Any:
return None
elif isinstance(obj, PRIMITIVE_TYPES):
return obj
elif isinstance(obj, Decimal):
return float(obj)
elif isinstance(obj, list):
return [body_serializer(sub_obj) for sub_obj in obj]
elif isinstance(obj, tuple):
Expand Down
Loading