Skip to content

Commit 92d94e3

Browse files
authored
fix(python): missing Decimal to float conversion for body serializer (#4618)
1 parent 86a562d commit 92d94e3

File tree

1 file changed

+4
-0
lines changed
  • clients/algoliasearch-client-python/algoliasearch/http

1 file changed

+4
-0
lines changed

clients/algoliasearch-client-python/algoliasearch/http/serializer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from decimal import Decimal
12
from json import dumps
23
from typing import Any, Dict, Optional
34
from urllib.parse import urlencode
@@ -42,6 +43,7 @@ def body_serializer(obj: Any) -> Any:
4243
4344
If obj is None, return None.
4445
If obj is str, int, long, float, bool, return directly.
46+
If obj is Decimal, convert to float and return.
4547
If obj is list, sanitize each element in the list.
4648
If obj is dict, return the dict.
4749
If obj is OpenAPI model, return the properties dict.
@@ -54,6 +56,8 @@ def body_serializer(obj: Any) -> Any:
5456
return None
5557
elif isinstance(obj, PRIMITIVE_TYPES):
5658
return obj
59+
elif isinstance(obj, Decimal):
60+
return float(obj)
5761
elif isinstance(obj, list):
5862
return [body_serializer(sub_obj) for sub_obj in obj]
5963
elif isinstance(obj, tuple):

0 commit comments

Comments
 (0)