mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
fix(proxy): avoid mutating container responses
This commit is contained in:
parent
7b1e3f278b
commit
20eb9c96ca
2 changed files with 30 additions and 1 deletions
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue