mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
fix(proxy): preserve opted-in environment variable saves
This commit is contained in:
parent
af17691389
commit
463ece762a
2 changed files with 20 additions and 8 deletions
|
|
@ -4944,14 +4944,7 @@ class ProxyConfig:
|
|||
await prisma_client.insert_data(data=unmanaged_config, table_name="config")
|
||||
|
||||
environment_variables: Final = new_config.get("environment_variables")
|
||||
if (
|
||||
include_env_vars
|
||||
and environment_variables is not None
|
||||
and (
|
||||
"environment_variables" not in baseline
|
||||
or baseline["environment_variables"] != environment_variables
|
||||
)
|
||||
):
|
||||
if include_env_vars and environment_variables is not None:
|
||||
encrypted_environment_variables: Final = (
|
||||
self._encrypt_env_variables_for_db(environment_variables=environment_variables)
|
||||
if isinstance(environment_variables, dict) and environment_variables
|
||||
|
|
|
|||
|
|
@ -1245,6 +1245,25 @@ async def test_ProxyConfig_save_config_db_persists_environment_variables_when_op
|
|||
assert table.upserted_param_names == ["environment_variables"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ProxyConfig_save_config_persists_unchanged_environment_variables_when_opted_in(monkeypatch):
|
||||
proxy_config, table = _db_backed_proxy_config(monkeypatch, {})
|
||||
config: Final = {
|
||||
"litellm_settings": {},
|
||||
"environment_variables": {"OPENAI_API_KEY": "sk-explicit"},
|
||||
}
|
||||
|
||||
await proxy_config.save_config(config)
|
||||
|
||||
assert table.rows == {}
|
||||
assert table.upserted_param_names == []
|
||||
|
||||
await proxy_config.save_config(config, include_env_vars=True)
|
||||
|
||||
assert set(table.rows["environment_variables"]) == {"OPENAI_API_KEY"}
|
||||
assert table.upserted_param_names == ["environment_variables"]
|
||||
|
||||
|
||||
def _install_fake_config_repo(monkeypatch, existing_row):
|
||||
"""Route ProxyConfig's ConfigRepository through an in-memory fake that
|
||||
records the value written to the environment_variables row."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue