diff --git a/getstream/utils/__init__.py b/getstream/utils/__init__.py index 5227149f..3b0e07b4 100644 --- a/getstream/utils/__init__.py +++ b/getstream/utils/__init__.py @@ -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 @@ -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: @@ -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) else: # For dictionaries or any other types of objects params[key] = json.dumps(value) @@ -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: diff --git a/tests/test_decoding.py b/tests/test_decoding.py index 07bea3d3..b4974414 100644 --- a/tests/test_decoding.py +++ b/tests/test_decoding.py @@ -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"}', } diff --git a/tests/test_query_params.py b/tests/test_query_params.py new file mode 100644 index 00000000..8aa96e6b --- /dev/null +++ b/tests/test_query_params.py @@ -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)