diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 920e7989d14..80d9868ff0e 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -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 diff --git a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py b/tests/test_litellm/proxy/proxy_server/test_proxy_config.py index 1693c0385af..9ba881ac30b 100644 --- a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py +++ b/tests/test_litellm/proxy/proxy_server/test_proxy_config.py @@ -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."""