diff --git a/litellm/proxy/container_endpoints/ownership.py b/litellm/proxy/container_endpoints/ownership.py index edb1b65c715..05634d506b7 100644 --- a/litellm/proxy/container_endpoints/ownership.py +++ b/litellm/proxy/container_endpoints/ownership.py @@ -73,7 +73,7 @@ def _get_response_id(response: Any) -> Optional[str]: def _dump_response(response: Any) -> Dict[str, Any]: if isinstance(response, dict): - return response + return dict(response) if hasattr(response, "model_dump"): return response.model_dump() if hasattr(response, "dict"): diff --git a/tests/test_litellm/containers/test_container_proxy_ownership.py b/tests/test_litellm/containers/test_container_proxy_ownership.py index 576e25bbbad..8ebfd3ab6f7 100644 --- a/tests/test_litellm/containers/test_container_proxy_ownership.py +++ b/tests/test_litellm/containers/test_container_proxy_ownership.py @@ -57,6 +57,35 @@ async def test_should_record_container_owner_with_original_provider_id(monkeypat assert data["created_by"] == "user-1" +@pytest.mark.asyncio +async def test_should_not_mutate_dict_container_response_when_recording_owner( + monkeypatch, +): + table = AsyncMock() + table.find_unique.return_value = None + prisma_client = SimpleNamespace( + db=SimpleNamespace(litellm_managedobjecttable=table) + ) + monkeypatch.setattr( + ownership, + "_get_prisma_client", + AsyncMock(return_value=prisma_client), + ) + auth = UserAPIKeyAuth(user_id="user-1") + response = {"id": "cntr_provider", "object": "container"} + + returned = await ownership.record_container_owner( + response=response, + user_api_key_dict=auth, + custom_llm_provider="openai", + ) + + assert returned == {"id": "cntr_provider", "object": "container"} + data = table.create.await_args.kwargs["data"] + assert data["file_object"]["custom_llm_provider"] == "openai" + assert data["file_object"]["provider_container_id"] == "cntr_provider" + + @pytest.mark.asyncio async def test_should_record_team_owner_for_keys_without_user_id(monkeypatch): table = AsyncMock()