fix(proxy_server.py): handle config containing thread locked objects when using get_config_state

This commit is contained in:
Krrish Dholakia 2025-01-12 08:51:17 -08:00 • committed by Ishaan Jaff
parent c35c137ac1
commit 74bc77b176
2 changed files with 25 additions and 2 deletions

View file

@ -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 {}

View file

@ -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",
[