diff --git a/aiola/clients/stt/client.py b/aiola/clients/stt/client.py index a88c978..59cd37e 100644 --- a/aiola/clients/stt/client.py +++ b/aiola/clients/stt/client.py @@ -34,7 +34,9 @@ def __init__(self, options: AiolaClientOptions, auth: AuthClient | AsyncAuthClie def _build_url(self, query_params: dict[str, str]) -> str: """Return base URL with encoded query parameters.""" try: - return f"{self._options.base_url}?{urlencode(query_params)}" + # Filter out None values from query parameters + filtered_params = {k: v for k, v in query_params.items() if v is not None} + return f"{self._options.base_url}?{urlencode(filtered_params)}" except Exception as exc: raise AiolaError("Failed to build streaming URL") from exc @@ -66,7 +68,7 @@ def _build_query_and_headers( "lang_code": lang_code or "en", "time_zone": time_zone or "UTC", "keywords": json.dumps(keywords or {}), - "tasks_config": json.dumps(tasks_config or {}), + "tasks_config": json.dumps(tasks_config) if tasks_config is not None else None, "x-aiola-api-token": access_token, } diff --git a/tests/unit/stt/test_stt_client.py b/tests/unit/stt/test_stt_client.py index 8780cbc..96c2687 100644 --- a/tests/unit/stt/test_stt_client.py +++ b/tests/unit/stt/test_stt_client.py @@ -341,15 +341,14 @@ def test_stt_stream_with_no_tasks_config(patch_dummy_socket): # Access the underlying socket to validate connection parameters sio = connection._sio - # Verify None tasks_config is serialized as empty JSON object + # Verify None tasks_config is excluded from URL parameters kwargs = sio.connect_kwargs url = kwargs["url"] parsed = urllib.parse.urlparse(url) query = urllib.parse.parse_qs(parsed.query) - tasks_config_json = query["tasks_config"][0] - parsed_tasks_config = json.loads(tasks_config_json) - assert parsed_tasks_config == {} + # tasks_config should not be present in query parameters when None + assert "tasks_config" not in query def test_stt_stream_with_all_tasks_config(patch_dummy_socket):