From 839ae71e228d4363181820a1d718e4f788b529be Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Sat, 10 Oct 2026 19:40:04 +0000 Subject: [PATCH] fix: stop double-encoding list query parameters --- getstream/utils/__init__.py | 7 +++---- tests/test_decoding.py | 2 +- tests/test_query_params.py | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/test_query_params.py diff --git a/getstream/utils/__init__.py b/getstream/utils/__init__.py index f1daec6b..342ee90a 100644 --- a/getstream/utils/__init__.py +++ b/getstream/utils/__init__.py @@ -1,7 +1,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 @@ -110,7 +109,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: @@ -132,7 +131,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) @@ -148,7 +147,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 1a2c2795..ed3a1019 100644 --- a/tests/test_decoding.py +++ b/tests/test_decoding.py @@ -37,7 +37,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)