From d91c66bcd7d8ab0b80c10c77abd146bb925eab98 Mon Sep 17 00:00:00 2001 From: waeckerlinfederowicz66-sketch Date: Tue, 27 Oct 2026 13:07:32 +0800 Subject: [PATCH] fix: avoid recursion in request log signature detection --- litellm/utils.py | 10 +++-- .../test_text_to_speech_transformation.py | 9 +++- tests/unit/test_utils.py | 45 +++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index a403300fe93..1923b67a648 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -8541,19 +8541,23 @@ def get_valid_models( return [] # NON-Blocking -def _request_logging_parameters(original_function: Callable[..., object]) -> tuple[str, ...]: +def _positional_request_parameter_names(original_function: Callable[..., object]) -> tuple[str, ...]: parameters: Final = inspect.signature(original_function).parameters.values() - positional: Final = tuple( + return tuple( parameter.name for parameter in parameters if parameter.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD) ) + + +def _request_logging_parameters(original_function: Callable[..., object]) -> tuple[str, ...]: + positional: Final = _positional_request_parameter_names(original_function) if positional or not inspect.iscoroutinefunction(original_function): return positional if original_function.__name__.startswith("a"): synchronous: Final = getattr(inspect.getmodule(original_function), original_function.__name__[1:], None) if callable(synchronous) and not inspect.iscoroutinefunction(synchronous): - return _request_logging_parameters(synchronous) + return _positional_request_parameter_names(synchronous) return () diff --git a/tests/unit/llms/flowspeech/test_text_to_speech_transformation.py b/tests/unit/llms/flowspeech/test_text_to_speech_transformation.py index c60ba4bff82..c2d5fba1340 100644 --- a/tests/unit/llms/flowspeech/test_text_to_speech_transformation.py +++ b/tests/unit/llms/flowspeech/test_text_to_speech_transformation.py @@ -232,7 +232,9 @@ def test_gateway_base_preserves_prefix_without_duplicating_endpoint(base, expect @pytest.mark.parametrize("prefix", ["/p%2Fq", "/p%2fq", "/p%252Fq", "/p%3Fq", "/p%23q"]) @pytest.mark.parametrize("suffix", ["/", "/api/v1/tts/jobs", "/api/v1/tts/jobs/"]) def test_gateway_prefix_preserves_encoded_path(prefix, suffix): - url = FlowSpeechTextToSpeechConfig().get_complete_url("flowspeech-tts", f"https://gateway.example{prefix}{suffix}", {}) + url = FlowSpeechTextToSpeechConfig().get_complete_url( + "flowspeech-tts", f"https://gateway.example{prefix}{suffix}", {} + ) assert httpx.URL(url).raw_path == f"{prefix}/api/v1/tts/jobs".encode("ascii") assert httpx.URL(url).query == b"" assert httpx.URL(url).fragment == "" @@ -426,7 +428,7 @@ async def test_positional_key_debug_controls( assert request.headers["authorization"] == f"Bearer {SECRET_SENTINEL}" return httpx.Response(400, json={"error": {"code": "synthetic", "message": "synthetic", "retryable": False}}) - with pytest.raises(litellm.BadRequestError if asynchronous else FlowSpeechException) as error: + async def call() -> None: if asynchronous: async with httpx.AsyncClient(transport=httpx.MockTransport(respond)) as client: await litellm.aspeech( @@ -437,6 +439,9 @@ async def test_positional_key_debug_controls( litellm.speech( "flowspeech/flowspeech-tts", "Hello", "Kore", SECRET_SENTINEL, client=client, max_retries=0 ) + + with pytest.raises(litellm.BadRequestError if asynchronous else FlowSpeechException) as error: + await call() captured: Final = capsys.readouterr() assert SECRET_SENTINEL not in caplog.text + captured.out + captured.err assert ("Request to litellm:" in caplog.text) is debug diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 8fc72fc748b..b6f97e64049 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -7049,6 +7049,51 @@ class TestVerboseRequestLineRedaction: assert self.FAKE_API_KEY not in caplog.text assert "litellm.opaque('REDACTED', model='synthetic-model')" in caplog.text + @pytest.mark.parametrize("async_prefix", [False, True]) + def test_async_varargs_without_sync_signature_hide_credentials( + self, + async_prefix: bool, + caplog: pytest.LogCaptureFixture, + ) -> None: + from litellm.utils import print_args_passed_to_litellm + + async def opaque_async(*args: object, **kwargs: object) -> None: + pass + + async def aopaque(*args: object, **kwargs: object) -> None: + pass + + function: Final = aopaque if async_prefix else opaque_async + with caplog.at_level(logging.DEBUG, logger=verbose_logger.name): + print_args_passed_to_litellm(function, (self.FAKE_API_KEY,), {"model": "synthetic-model"}) + assert self.FAKE_API_KEY not in caplog.text + assert f"litellm.{function.__name__}('REDACTED', model='synthetic-model')" in caplog.text + + @pytest.mark.parametrize("error_type", [TypeError, ValueError]) + def test_unavailable_signature_hides_all_positional_values( + self, + error_type: type[Exception], + caplog: pytest.LogCaptureFixture, + ) -> None: + from litellm.utils import print_args_passed_to_litellm + + class OpaqueCallable: + __name__ = "opaque" + + @property + def __signature__(self) -> inspect.Signature: + raise error_type("signature unavailable") + + def __call__(self, *args: object, **kwargs: object) -> None: + pass + + with caplog.at_level(logging.DEBUG, logger=verbose_logger.name): + print_args_passed_to_litellm( + OpaqueCallable(), (self.FAKE_API_KEY, self.FAKE_API_KEY), {"model": "synthetic-model"} + ) + assert self.FAKE_API_KEY not in caplog.text + assert "litellm.opaque('REDACTED', 'REDACTED', model='synthetic-model')" in caplog.text + def test_positional_only_and_surplus_arguments_are_sanitized( self, caplog: pytest.LogCaptureFixture,