Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions getstream/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import asyncio
from typing import Dict, List, Optional, Union, cast
from urllib.parse import quote
from datetime import datetime
from datetime import timezone
from urllib.parse import urlparse, urlunparse
Expand Down Expand Up @@ -120,7 +119,7 @@ def build_query_param(**kwargs):
- JSON-serializable objects with a `to_json` method will be serialized using that method.
- datetime objects are converted to ISO 8601 strings.
- Booleans are converted to lowercase strings.
- Lists are converted to comma-separated strings with URL-encoded values.
- Lists are converted to comma-separated strings.
- Other types (strings, integers, dictionaries) are handled appropriately.

Args:
Expand All @@ -142,7 +141,7 @@ def build_query_param(**kwargs):
elif isinstance(value, (str, int)):
params[key] = str(value)
elif isinstance(value, list):
params[key] = ",".join(quote(_serialize_query_value(v)) for v in value)
params[key] = ",".join(_serialize_query_value(v) for v in value)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
else:
# For dictionaries or any other types of objects
params[key] = json.dumps(value)
Expand All @@ -158,7 +157,7 @@ async def build_query_param_async(**kwargs):
This function handles various data types:
- JSON-serializable objects with a `to_json` method will be serialized using that method.
- Booleans are converted to lowercase strings.
- Lists are converted to comma-separated strings with URL-encoded values.
- Lists are converted to comma-separated strings.
- Other types (strings, integers, dictionaries) are handled appropriately.

Args:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_build_query_param_with_various_types():
"num": "123",
"text": "hello",
"flag": "true",
"list_val": "1,2,three%2C%20maybe",
"list_val": "1,2,three, maybe",
"obj": '{"type": "Mock"}',
"dict_val": '{"a": 1, "b": "two"}',
}
Expand Down
27 changes: 27 additions & 0 deletions tests/test_query_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import httpx

from getstream import Stream


class Recorder:
def __init__(self):
self.requests = []

def __call__(self, request: httpx.Request) -> httpx.Response:
self.requests.append(request)
return httpx.Response(200, json={"duration": "0ms", "collections": []})


REFS = ["food:pizza", "user@example.com", "a b"]


def test_list_query_params_are_encoded_once():
recorder = Recorder()
client = Stream(
api_key="key", api_secret="secret", transport=httpx.MockTransport(recorder)
)

client.feeds.read_collections(collection_refs=REFS)

(request,) = recorder.requests
assert request.url.params["collection_refs"] == ",".join(REFS)
Loading