fix(proxy): preserve opted-in environment variable saves

This commit is contained in:
Yuneng Jiang 2026-09-17 20:53:21 -07:00
parent af17691389
commit 463ece762a
No known key found for this signature in database
2 changed files with 20 additions and 8 deletions

View file

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

View file

@ -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."""