LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
UN-2640 [FIX] Resolve empty task_id causing 404 status API errors (#1453)
ali8000a8003bd8
diff --git a/backend/workflow_manager/workflow_v2/exceptions.py b/backend/workflow_manager/workflow_v2/exceptions.pyindex 6f52081f8..d6b10ede3 100644--- a/backend/workflow_manager/workflow_v2/exceptions.py+++ b/backend/workflow_manager/workflow_v2/exceptions.py@@ -26,11 +26,6 @@ class ExecutionDoesNotExistError(APIException):default_detail = "Execution does not exist."-class TaskDoesNotExistError(APIException):- status_code = 404- default_detail = "Task does not exist"--class DuplicateActionError(APIException):status_code = 400default_detail = "Action is running"diff --git a/backend/workflow_manager/workflow_v2/execution.py b/backend/workflow_manager/workflow_v2/execution.pyindex 34dd2931e..3de4cb6c1 100644--- a/backend/workflow_manager/workflow_v2/execution.py+++ b/backend/workflow_manager/workflow_v2/execution.py@@ -404,15 +404,22 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):@staticmethoddef update_execution_task(execution_id: str, task_id: str) -> None:try:+ logger.info(+ f"Updating task_id for execution {execution_id} with task_id {task_id}"+ )if not task_id:logger.warning(- f"task_id: '{task_id}' is NULL / empty for "- f"execution_id: {execution_id}, expected to have a UUID"+ f"Skipped setting task_id for execution {execution_id} since its NULL/empty")+ return # Don't save empty task_id+execution = WorkflowExecution.objects.get(pk=execution_id)# TODO: Review if status should be updated to EXECUTINGexecution.task_id = task_id- execution.save()+ execution.save(update_fields=["task_id"])+ logger.info(+ f"Successfully set task_id '{task_id}' for execution {execution_id}"+ )except WorkflowExecution.DoesNotExist:logger.error(f"execution doesn't exist {execution_id}")diff --git a/backend/workflow_manager/workflow_v2/workflow_helper.py b/backend/workflow_manager/workflow_v2/workflow_helper.pyindex b0b7ac2b6..dc7409432 100644--- a/backend/workflow_manager/workflow_v2/workflow_helper.py+++ b/backend/workflow_manager/workflow_v2/workflow_helper.py@@ -55,7 +55,6 @@ from workflow_manager.workflow_v2.enums import ()from workflow_manager.workflow_v2.exceptions import (InvalidRequest,- TaskDoesNotExistError,WorkflowDoesNotExistError,WorkflowExecutionError,WorkflowExecutionNotExist,@@ -343,16 +342,12 @@ class WorkflowHelper:execution_id (str): workflow execution idRaises:- TaskDoesNotExistError: Not found exceptionExecutionDoesNotExistError: If execution is not foundReturns:ExecutionResponse: _description_"""execution: WorkflowExecution = WorkflowExecution.objects.get(id=execution_id)- if not execution.task_id:- raise TaskDoesNotExistError(f"No task ID found for execution: {execution_id}")-task_result = Noneresult_acknowledged = execution.result_acknowledged# Prepare the initial response with the task's current status and result.@@ -473,15 +468,32 @@ class WorkflowHelper:},queue=queue,)++ # Log task_id for debugginglogger.info(- f"[{org_schema}] Job '{async_execution}' has been enqueued for "- f"execution_id '{execution_id}', '{len(hash_values_of_files)}' files"+ f"[{org_schema}] AsyncResult created with task_id: '{async_execution.id}' "+ f"(type: {type(async_execution.id).__name__})")+workflow_execution: WorkflowExecution = WorkflowExecution.objects.get(id=execution_id)- workflow_execution.task_id = async_execution.id- workflow_execution.save()++ # Handle empty task_id gracefully using existing validation logic+ if not async_execution.id:+ logger.warning(+ f"[{org_schema}] Celery returned empty task_id for execution_id '{execution_id}'. "+ )+ # Continue without setting task_id - execution can still complete+ else:+ # Use existing method to handle task_id setting with validation+ WorkflowExecutionServiceHelper.update_execution_task(+ execution_id=execution_id, task_id=async_execution.id+ )+ logger.info(+ f"[{org_schema}] Job '{async_execution.id}' has been enqueued for "+ f"execution_id '{execution_id}', '{len(hash_values_of_files)}' files"+ )execution_status = workflow_execution.statusif timeout > -1:while not ExecutionStatus.is_completed(execution_status) and timeout > 0: