From d585668d21ffaf588af77a48868bcbb110ab007a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 14 Aug 2026 01:36:18 +0000 Subject: [PATCH 1/2] test(mcp): patch prisma-client resolver in temporary-session tests After #36844, get_cached_temporary_mcp_server and add_session_mcp_server route through _get_prisma_client_or_none() and try a DB draft lookup on an in-memory cache miss. Three pre-existing tests in TestTemporaryMCPSessionEndpoints exercise those paths but never intended to hit the DB; they only ran green when proxy_server.prisma_client was None. When another test in the same proxy-endpoints CI shard leaves proxy_server.prisma_client set to a MagicMock, the draft-lookup path then awaits a MagicMock and fails with 'object MagicMock can't be used in await expression'. Pin those three tests to the no-database branch by patching _get_prisma_client_or_none to return None, matching what the tests actually exercise (in-memory prune, Redis fallback, and the redact-and- cache path of add_session_mcp_server). Co-authored-by: Krrish Dholakia --- .../test_mcp_management_endpoints.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py index b6c2fd4c8e3..848d2adc7a4 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py @@ -1688,9 +1688,15 @@ class TestTemporaryMCPSessionEndpoints: expires_at=datetime.utcnow() - timedelta(seconds=30), ) cache = {"expired": expired_entry} - with patch( - "litellm.proxy.management_endpoints.mcp_management_endpoints._temporary_mcp_servers", - cache, + with ( + patch( + "litellm.proxy.management_endpoints.mcp_management_endpoints._temporary_mcp_servers", + cache, + ), + patch( + "litellm.proxy.management_endpoints.mcp_management_endpoints._get_prisma_client_or_none", + return_value=None, + ), ): result = await get_cached_temporary_mcp_server("expired") @@ -2266,6 +2272,10 @@ class TestTemporaryMCPSessionEndpoints: "litellm.proxy.management_endpoints.mcp_management_endpoints.global_mcp_server_manager", mock_manager, ), + patch( + "litellm.proxy.management_endpoints.mcp_management_endpoints._get_prisma_client_or_none", + return_value=None, + ), patch( "litellm.proxy.management_endpoints.mcp_management_endpoints._cache_temporary_mcp_server", MagicMock(), @@ -3415,6 +3425,10 @@ class TestTemporaryMCPSessionEndpoints: "litellm.proxy.management_endpoints.mcp_management_endpoints._temporary_mcp_servers", {}, ), + patch( + "litellm.proxy.management_endpoints.mcp_management_endpoints._get_prisma_client_or_none", + return_value=None, + ), patch( "litellm.proxy.management_endpoints.mcp_management_endpoints.decrypt_value_helper", return_value=serialized, From 8329a32f3fe74474c9a703219364f052189c1a3d Mon Sep 17 00:00:00 2001 From: yassin Date: Fri, 14 Aug 2026 02:26:35 +0000 Subject: [PATCH 2/2] test(proxy): stop team-endpoint fixture leaking prisma_client global The autouse mock_db_client fixture used unittest.mock.patch while individual tests monkeypatch the same global, so monkeypatch snapshotted the fixture's MagicMock and its undo ran after the patch exited, leaving the mock installed for every later test in the worker. Sharing the monkeypatch instance makes the restore chain unwind back to the real value. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../proxy/management_endpoints/test_team_endpoints.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py index f038af4c7a1..7aa9a77c354 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py @@ -78,11 +78,9 @@ mock_prisma_client.db.litellm_teamtable.update = AsyncMock() # Fixture to provide the mock prisma client @pytest.fixture(autouse=True) -def mock_db_client(): - with patch( - "litellm.proxy.proxy_server.prisma_client", mock_prisma_client - ): # Mock in both places if necessary - yield mock_prisma_client +def mock_db_client(monkeypatch): + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", mock_prisma_client) + yield mock_prisma_client mock_prisma_client.reset_mock()