mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
Fix callback env variables
This commit is contained in:
parent
802a343fdb
commit
4bcbd8b0a9
2 changed files with 34 additions and 1 deletions
|
|
@ -3361,8 +3361,17 @@ class ProxyConfig:
|
|||
decrypted_env_vars = self._decrypt_and_set_db_env_variables(
|
||||
db_param_value, return_original_value=True
|
||||
)
|
||||
# Normalize keys when loading from DB so services expecting uppercase
|
||||
# (e.g. Datadog) can read them even if stored in lowercase.
|
||||
merged_env_vars: dict = {}
|
||||
for key, value in decrypted_env_vars.items():
|
||||
merged_env_vars[key] = value
|
||||
upper_key = key.upper()
|
||||
merged_env_vars[upper_key] = value
|
||||
os.environ[upper_key] = value
|
||||
|
||||
current_config.setdefault("environment_variables", {}).update(
|
||||
decrypted_env_vars
|
||||
merged_env_vars
|
||||
)
|
||||
return current_config
|
||||
elif param_name == "litellm_settings" and isinstance(db_param_value, dict):
|
||||
|
|
|
|||
|
|
@ -2609,6 +2609,30 @@ async def test_init_sso_settings_in_db_empty_settings():
|
|||
assert uppercased_settings == {}
|
||||
|
||||
|
||||
def test_update_config_fields_uppercases_env_vars(monkeypatch):
|
||||
"""
|
||||
Ensure environment variables pulled from DB are uppercased when applied so
|
||||
integrations like Datadog that expect uppercase env keys can read them.
|
||||
"""
|
||||
from litellm.proxy.proxy_server import ProxyConfig
|
||||
|
||||
for key in ["DD_API_KEY", "DD_SITE", "dd_api_key", "dd_site"]:
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
|
||||
proxy_config = ProxyConfig()
|
||||
updated_config = proxy_config._update_config_fields(
|
||||
current_config={},
|
||||
param_name="environment_variables",
|
||||
db_param_value={"dd_api_key": "test-api-key", "dd_site": "us5.datadoghq.com"},
|
||||
)
|
||||
|
||||
env_vars = updated_config.get("environment_variables", {})
|
||||
assert env_vars["DD_API_KEY"] == "test-api-key"
|
||||
assert env_vars["DD_SITE"] == "us5.datadoghq.com"
|
||||
assert os.environ.get("DD_API_KEY") == "test-api-key"
|
||||
assert os.environ.get("DD_SITE") == "us5.datadoghq.com"
|
||||
|
||||
|
||||
def test_get_prompt_spec_for_db_prompt_with_versions():
|
||||
"""
|
||||
Test that _get_prompt_spec_for_db_prompt correctly converts database prompts
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue