From 74bc77b176e0160778d1274e9429a5cb921bfb8e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sun, 12 Jan 2025 08:51:17 -0800 Subject: [PATCH] fix(proxy_server.py): handle config containing thread locked objects when using get_config_state --- litellm/proxy/proxy_server.py | 4 ++-- tests/proxy_unit_tests/test_proxy_utils.py | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 8002863217d..e337222199a 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1657,8 +1657,8 @@ class ProxyConfig: return copy.deepcopy(self.config) except Exception as e: verbose_proxy_logger.debug( - "ProxyConfig:get_config_state(): Error returning copy of config state. self.config={}\nError: {}".format( - self.config, e + "ProxyConfig:get_config_state(): Error returning copy of config state. self.config={}".format( + self.config ) ) return {} diff --git a/tests/proxy_unit_tests/test_proxy_utils.py b/tests/proxy_unit_tests/test_proxy_utils.py index dd018f674ff..2b63ba5a8b8 100644 --- a/tests/proxy_unit_tests/test_proxy_utils.py +++ b/tests/proxy_unit_tests/test_proxy_utils.py @@ -1107,6 +1107,29 @@ def test_proxy_config_state_post_init_callback_call(): assert config["litellm_settings"]["default_team_settings"][0]["team_id"] == "test" +def test_proxy_config_state_get_config_state_error(): + """ + Ensures that get_config_state does not raise an error when the config is not a valid dictionary + """ + from litellm.proxy.proxy_server import ProxyConfig + import threading + + test_config = { + "callback_list": [ + { + "lock": threading.RLock(), # This will cause the deep copy to fail + "name": "test_callback", + } + ], + "model_list": ["gpt-4", "claude-3"], + } + + pc = ProxyConfig() + pc.config = test_config + config = pc.get_config_state() + assert config == {} + + @pytest.mark.parametrize( "associated_budget_table, expected_user_api_key_auth_key, expected_user_api_key_auth_value", [