diff --git a/spiffworkflow-backend/.gitignore b/spiffworkflow-backend/.gitignore index 807a7557..a4a16fa4 100644 --- a/spiffworkflow-backend/.gitignore +++ b/spiffworkflow-backend/.gitignore @@ -20,3 +20,4 @@ node_modules /src/spiffworkflow_backend/config/secrets.py *null-ls_* /local_wheels/*.whl +/some_cache_dir diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/error_handling_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/error_handling_service.py index 66a4e424..ce92466c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/error_handling_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/error_handling_service.py @@ -1,11 +1,9 @@ from flask import current_app from flask import g from spiffworkflow_backend.models.db import db -from spiffworkflow_backend.models.message_instance import MessageInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus from spiffworkflow_backend.models.process_model import ProcessModelInfo -from spiffworkflow_backend.services.message_service import MessageService from spiffworkflow_backend.services.process_model_service import ProcessModelService @@ -57,6 +55,12 @@ class ErrorHandlingService: process_instance: ProcessInstanceModel, ) -> None: """Send a BPMN Message - which may kick off a waiting process.""" + + # importing here to avoid circular imports since these imports are only needed here at runtime. + # we were not able to figure out which specific import was causing the issue. + from spiffworkflow_backend.models.message_instance import MessageInstanceModel + from spiffworkflow_backend.services.message_service import MessageService + message_text = ( f"There was an exception running process {process_model.id}.\nOriginal Error:\n{error.__repr__()}" ) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_queue_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_queue_service.py index 16bed6f5..0ab6c8cf 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_queue_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_queue_service.py @@ -4,9 +4,9 @@ from collections.abc import Generator from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.process_instance import ProcessInstanceModel -from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus from spiffworkflow_backend.models.process_instance_event import ProcessInstanceEventType from spiffworkflow_backend.models.process_instance_queue import ProcessInstanceQueueModel +from spiffworkflow_backend.services.error_handling_service import ErrorHandlingService from spiffworkflow_backend.services.process_instance_lock_service import ProcessInstanceLockService from spiffworkflow_backend.services.process_instance_tmp_service import ProcessInstanceTmpService from spiffworkflow_backend.services.workflow_execution_service import WorkflowExecutionServiceError @@ -97,15 +97,13 @@ class ProcessInstanceQueueService: try: yield except Exception as ex: - process_instance.status = ProcessInstanceStatus.error.value - db.session.add(process_instance) # these events are handled in the WorkflowExecutionService. # that is, we don't need to add error_detail records here, etc. if not isinstance(ex, WorkflowExecutionServiceError): ProcessInstanceTmpService.add_event_to_process_instance( process_instance, ProcessInstanceEventType.process_instance_error.value, exception=ex ) - db.session.commit() + ErrorHandlingService.handle_error(process_instance, ex) raise ex finally: if not reentering_lock: diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_error_handling_service.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_error_handling_service.py index 34f26373..b9d07ac1 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_error_handling_service.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_error_handling_service.py @@ -6,7 +6,6 @@ from spiffworkflow_backend.models.message_instance import MessageInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus from spiffworkflow_backend.models.process_model import ProcessModelInfo -from spiffworkflow_backend.services.error_handling_service import ErrorHandlingService from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.workflow_execution_service import WorkflowExecutionServiceError @@ -24,9 +23,10 @@ class TestErrorHandlingService(BaseTest): def run_process_model_and_handle_error(self, process_model: ProcessModelInfo) -> ProcessInstanceModel: process_instance = self.create_process_instance_from_process_model(process_model) pip = ProcessInstanceProcessor(process_instance) - with pytest.raises(WorkflowExecutionServiceError) as e: + + # the error handler will be called from dequeued within do_engine_steps now + with pytest.raises(WorkflowExecutionServiceError): pip.do_engine_steps(save=True) - ErrorHandlingService().handle_error(process_instance, e.value) return process_instance def test_handle_error_suspends_or_faults_process(