make process metadata saving more resilient

This commit is contained in:
burnettk 2022-12-08 08:44:31 -05:00
parent 0fc136a6dd
commit 829eacc40d
1 changed files with 16 additions and 11 deletions

View File

@ -595,20 +595,25 @@ class ProcessInstanceProcessor:
path_segments = path.split(".") path_segments = path.split(".")
data_for_key = current_data data_for_key = current_data
for path_segment in path_segments: 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( if data_for_key is not None:
process_instance_id=self.process_instance_model.id, pim = ProcessInstanceMetadataModel.query.filter_by(
key=key,
).first()
if pim is None:
pim = ProcessInstanceMetadataModel(
process_instance_id=self.process_instance_model.id, process_instance_id=self.process_instance_model.id,
key=key, key=key,
) ).first()
pim.value = data_for_key if pim is None:
db.session.add(pim) pim = ProcessInstanceMetadataModel(
db.session.commit() 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: def save(self) -> None:
"""Saves the current state of this processor to the database.""" """Saves the current state of this processor to the database."""