From c5e7e91533702e1d45e964156326deac76ec1fd5 Mon Sep 17 00:00:00 2001 From: burnettk Date: Thu, 8 Dec 2022 08:44:31 -0500 Subject: [PATCH] make process metadata saving more resilient --- .../services/process_instance_processor.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index 1be46f1b..e833d8af 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -595,20 +595,25 @@ class ProcessInstanceProcessor: path_segments = path.split(".") data_for_key = current_data for path_segment in path_segments: - data_for_key = data_for_key[path_segment] + if path_segment in data_for_key: + data_for_key = data_for_key[path_segment] + else: + data_for_key = None + break - pim = ProcessInstanceMetadataModel.query.filter_by( - process_instance_id=self.process_instance_model.id, - key=key, - ).first() - if pim is None: - pim = ProcessInstanceMetadataModel( + if data_for_key is not None: + pim = ProcessInstanceMetadataModel.query.filter_by( process_instance_id=self.process_instance_model.id, key=key, - ) - pim.value = data_for_key - db.session.add(pim) - db.session.commit() + ).first() + if pim is None: + pim = ProcessInstanceMetadataModel( + process_instance_id=self.process_instance_model.id, + key=key, + ) + pim.value = data_for_key + db.session.add(pim) + db.session.commit() def save(self) -> None: """Saves the current state of this processor to the database."""