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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
openai.ConflictError
Ishaan Jaff3e13f8dd0f6c
diff --git a/tests/batches_tests/test_openai_batches_and_files.py b/tests/batches_tests/test_openai_batches_and_files.pyindex b2826419e8b..67ce2f7249a 100644--- a/tests/batches_tests/test_openai_batches_and_files.py+++ b/tests/batches_tests/test_openai_batches_and_files.py@@ -15,12 +15,14 @@ sys.path.insert(import loggingimport time+import asyncioimport pytestfrom typing import Optionalimport litellmfrom litellm import create_batch, create_filefrom litellm._logging import verbose_logger+import openaiverbose_logger.setLevel(logging.DEBUG)@@ -146,12 +148,24 @@ async def test_create_batch(provider):with open(result_file_name, "wb") as file:file.write(result)- # Cancel Batch- cancel_batch_response = await litellm.acancel_batch(- batch_id=create_batch_response.id,- custom_llm_provider=provider,- )- print("cancel_batch_response=", cancel_batch_response)+ # Cancel Batch - handle race condition where batch may already be completed+ try:+ cancel_batch_response = await litellm.acancel_batch(+ batch_id=create_batch_response.id,+ custom_llm_provider=provider,+ )+ print("cancel_batch_response=", cancel_batch_response)+ except openai.ConflictError as e:+ # Only allow to pass if it's specifically the "batch already completed" error+ if "Cannot cancel a batch with status 'completed'" in str(e):+ print(f"Batch already completed, cannot cancel: {e}")+ else:+ # Re-raise other ConflictError types+ raise+ except Exception as e:+ # Re-raise any other unexpected errors+ print(f"Unexpected error during batch cancellation: {e}")+ raisepass@@ -355,12 +369,24 @@ async def test_async_create_batch(provider):with open(result_file_name, "wb") as file:file.write(file_content.content)- # Cancel Batch- cancel_batch_response = await litellm.acancel_batch(- batch_id=create_batch_response.id,- custom_llm_provider=provider,- )- print("cancel_batch_response=", cancel_batch_response)+ # Cancel Batch - handle race condition where batch may already be completed+ try:+ cancel_batch_response = await litellm.acancel_batch(+ batch_id=create_batch_response.id,+ custom_llm_provider=provider,+ )+ print("cancel_batch_response=", cancel_batch_response)+ except openai.ConflictError as e:+ # Only allow to pass if it's specifically the "batch already completed" error+ if "Cannot cancel a batch with status 'completed'" in str(e):+ print(f"Batch already completed, cannot cancel: {e}")+ else:+ # Re-raise other ConflictError types+ raise+ except Exception as e:+ # Re-raise any other unexpected errors+ print(f"Unexpected error during batch cancellation: {e}")+ raiseif random.randint(1, 3) == 1:print("Running random cleanup of Azure files and models...")