prevent backfill from exploding when a primary file name on another model does not exist

This commit is contained in:
burnettk 2022-11-03 16:55:10 -04:00
parent bad6341dcf
commit 65566086dc
2 changed files with 22 additions and 7 deletions

View File

@ -94,6 +94,9 @@ from spiffworkflow_backend.scripts.script import Script
from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.file_system_service import FileSystemService
from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.process_model_service import ProcessModelService
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate 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.spec_file_service import SpecFileService
from spiffworkflow_backend.services.user_service import UserService from spiffworkflow_backend.services.user_service import UserService
@ -669,10 +672,14 @@ class ProcessInstanceProcessor:
process_models = ProcessModelService().get_process_models() process_models = ProcessModelService().get_process_models()
for process_model in process_models: for process_model in process_models:
if process_model.primary_file_name: if process_model.primary_file_name:
etree_element = SpecFileService.get_etree_element_from_file_name( try:
process_model, process_model.primary_file_name etree_element = SpecFileService.get_etree_element_from_file_name(
) process_model, process_model.primary_file_name
bpmn_process_identifiers = [] )
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: try:
bpmn_process_identifiers = ( bpmn_process_identifiers = (
@ -700,6 +707,11 @@ class ProcessInstanceProcessor:
bpmn_process_identifier: str, bpmn_process_identifier: str,
) -> str: ) -> str:
"""Bpmn_file_full_path_from_bpmn_process_identifier.""" """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_id_lookup = BpmnProcessIdLookup.query.filter_by(
bpmn_process_identifier=bpmn_process_identifier bpmn_process_identifier=bpmn_process_identifier
).first() ).first()

View File

@ -27,6 +27,10 @@ from spiffworkflow_backend.services.file_system_service import FileSystemService
from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.process_model_service import ProcessModelService
class ProcessModelFileNotFoundError(Exception):
"""ProcessModelFileNotFoundError."""
class SpecFileService(FileSystemService): class SpecFileService(FileSystemService):
"""SpecFileService.""" """SpecFileService."""
@ -90,9 +94,8 @@ class SpecFileService(FileSystemService):
"""Get_data.""" """Get_data."""
file_path = SpecFileService.file_path(process_model_info, file_name) file_path = SpecFileService.file_path(process_model_info, file_name)
if not os.path.exists(file_path): if not os.path.exists(file_path):
raise ApiError( raise ProcessModelFileNotFoundError(
"unknown_file", f"No file found with name {file_name} in {process_model_info.display_name}"
f"No file found with name {file_name} in {process_model_info.display_name}",
) )
with open(file_path, "rb") as f_handle: with open(file_path, "rb") as f_handle:
spec_file_data = f_handle.read() spec_file_data = f_handle.read()