Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(batches): cover caller-supplied db row skipping the cancel-path lookup

mateo-berri470ebc208991
diff --git a/tests/test_litellm/enterprise/proxy/test_batch_update_db_managed_output_file_id.py b/tests/test_litellm/enterprise/proxy/test_batch_update_db_managed_output_file_id.py
index 74139fa9238..1b60c97b510 100644
--- a/tests/test_litellm/enterprise/proxy/test_batch_update_db_managed_output_file_id.py
+++ b/tests/test_litellm/enterprise/proxy/test_batch_update_db_managed_output_file_id.py
@@ -127,6 +127,42 @@ async def test_cancel_path_registers_output_file_under_batch_owner():
assert stored["output_file_id"] == unified_id
+async def test_update_batch_skips_lookup_when_db_batch_object_supplied():
+ unified_id = "file-bWFuYWdlZF9vdXRwdXRfaWQ="
+ caller_row = SimpleNamespace(
+ created_by="caller-owner", team_id="caller-team", status="in_progress"
+ )
+ decoy_row = SimpleNamespace(
+ created_by="decoy-owner", team_id="decoy-team", status="in_progress"
+ )
+ response = _build_batch_response(
+ status="cancelling",
+ output_file_id="file-raw-output",
+ hidden_params={"model_id": "my-model", "model_name": "openai/gpt-4o"},
+ )
+ mock_managed_files = _build_managed_files_mock(unified_id=unified_id)
+ mock_prisma = _build_prisma_mock(db_batch_object=decoy_row)
+
+ await update_batch_in_database(
+ batch_id="batch_managed_ids_test",
+ unified_batch_id="litellm_proxy;model_id:my-model;llm_batch_id:batch_managed_ids_test",
+ response=response,
+ managed_files_obj=mock_managed_files,
+ prisma_client=mock_prisma,
+ verbose_proxy_logger=MagicMock(),
+ db_batch_object=caller_row,
+ operation="retrieve",
+ )
+
+ mock_prisma.db.litellm_managedobjecttable.find_first.assert_not_called()
+ forwarded_auth = mock_managed_files.store_unified_file_id.call_args.kwargs[
+ "user_api_key_dict"
+ ]
+ assert forwarded_auth.user_id == "caller-owner"
+ assert forwarded_auth.team_id == "caller-team"
+
+
@pytest.mark.asyncio
async def test_update_batch_derives_model_id_from_unified_batch_id():
unified_id = "file-bWFuYWdlZF9vdXRwdXRfaWQ="