From 65566086dc2f11999f8a13a9d0fdc83ccb805530 Mon Sep 17 00:00:00 2001 From: burnettk Date: Thu, 3 Nov 2022 16:55:10 -0400 Subject: [PATCH] prevent backfill from exploding when a primary file name on another model does not exist --- .../services/process_instance_processor.py | 20 +++++++++++++++---- .../services/spec_file_service.py | 9 ++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index dd80aa85a..35320f652 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -94,6 +94,9 @@ from spiffworkflow_backend.scripts.script import Script from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate +from spiffworkflow_backend.services.spec_file_service import ( + ProcessModelFileNotFoundError, +) from spiffworkflow_backend.services.spec_file_service import SpecFileService from spiffworkflow_backend.services.user_service import UserService @@ -669,10 +672,14 @@ class ProcessInstanceProcessor: process_models = ProcessModelService().get_process_models() for process_model in process_models: if process_model.primary_file_name: - etree_element = SpecFileService.get_etree_element_from_file_name( - process_model, process_model.primary_file_name - ) - bpmn_process_identifiers = [] + try: + etree_element = SpecFileService.get_etree_element_from_file_name( + process_model, process_model.primary_file_name + ) + bpmn_process_identifiers = [] + except ProcessModelFileNotFoundError: + # if primary_file_name doesn't actually exist on disk, then just go on to the next process_model + continue try: bpmn_process_identifiers = ( @@ -700,6 +707,11 @@ class ProcessInstanceProcessor: bpmn_process_identifier: str, ) -> str: """Bpmn_file_full_path_from_bpmn_process_identifier.""" + if bpmn_process_identifier is None: + raise ValueError( + "bpmn_file_full_path_from_bpmn_process_identifier: bpmn_process_identifier is unexpectedly None" + ) + bpmn_process_id_lookup = BpmnProcessIdLookup.query.filter_by( bpmn_process_identifier=bpmn_process_identifier ).first() diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py index 4e1e30e2f..eb2a322f9 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py @@ -27,6 +27,10 @@ from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.process_model_service import ProcessModelService +class ProcessModelFileNotFoundError(Exception): + """ProcessModelFileNotFoundError.""" + + class SpecFileService(FileSystemService): """SpecFileService.""" @@ -90,9 +94,8 @@ class SpecFileService(FileSystemService): """Get_data.""" file_path = SpecFileService.file_path(process_model_info, file_name) if not os.path.exists(file_path): - raise ApiError( - "unknown_file", - f"No file found with name {file_name} in {process_model_info.display_name}", + raise ProcessModelFileNotFoundError( + f"No file found with name {file_name} in {process_model_info.display_name}" ) with open(file_path, "rb") as f_handle: spec_file_data = f_handle.read()