diff --git a/litellm/proxy/container_endpoints/ownership.py b/litellm/proxy/container_endpoints/ownership.py index e3d8da8b0d..2260d67b62 100644 --- a/litellm/proxy/container_endpoints/ownership.py +++ b/litellm/proxy/container_endpoints/ownership.py @@ -219,11 +219,14 @@ def _set_container_list_data(response: Any, data: List[Any]) -> Any: else: response["first_id"] = None response["last_id"] = None + response["has_more"] = False return response response.data = data response.first_id = _get_response_id(data[0]) if data else None response.last_id = _get_response_id(data[-1]) if data else None + if not data and hasattr(response, "has_more"): + response.has_more = False return response diff --git a/tests/test_litellm/containers/test_container_proxy_ownership.py b/tests/test_litellm/containers/test_container_proxy_ownership.py index d0b755645d..40397a1886 100644 --- a/tests/test_litellm/containers/test_container_proxy_ownership.py +++ b/tests/test_litellm/containers/test_container_proxy_ownership.py @@ -233,6 +233,76 @@ async def test_should_filter_container_list_to_owned_records(monkeypatch): assert where["created_by"]["in"] == ["user-1", "user:user-1"] +@pytest.mark.asyncio +async def test_should_clear_has_more_when_filtered_container_list_is_empty( + monkeypatch, +): + table = AsyncMock() + table.find_many.return_value = [ + SimpleNamespace(model_object_id="container:openai:cntr_owned"), + ] + 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 = ContainerListResponse( + object="list", + data=[_container("cntr_other")], + has_more=True, + ) + + filtered = await ownership.filter_container_list_response( + response=response, + user_api_key_dict=auth, + custom_llm_provider="openai", + ) + + assert filtered.data == [] + assert filtered.first_id is None + assert filtered.last_id is None + assert filtered.has_more is False + + +@pytest.mark.asyncio +async def test_should_clear_dict_has_more_when_filtered_container_list_is_empty( + monkeypatch, +): + table = AsyncMock() + table.find_many.return_value = [ + SimpleNamespace(model_object_id="container:openai:cntr_owned"), + ] + 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 = { + "object": "list", + "data": [{"id": "cntr_other"}], + "has_more": True, + } + + filtered = await ownership.filter_container_list_response( + response=response, + user_api_key_dict=auth, + custom_llm_provider="openai", + ) + + assert filtered["data"] == [] + assert filtered["first_id"] is None + assert filtered["last_id"] is None + assert filtered["has_more"] is False + + @pytest.mark.asyncio async def test_should_filter_container_list_with_in_memory_ownership(monkeypatch): monkeypatch.setattr(