load-parent-task-data (#1447)

* load task data for the immediate completed parent and for cancelled tasks

* reverted query_tasks script

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
This commit is contained in:
jasquat 2024-04-24 18:08:31 +00:00 committed by GitHub
parent c2856be3bf
commit 1355c97b69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 4 deletions

View File

@ -92,10 +92,14 @@ class TaskModel(SpiffworkflowBaseDBModel):
def json_data(self) -> dict:
return JsonDataModel.find_data_dict_by_hash(self.json_data_hash)
def parent_task_model(self) -> TaskModel | None:
def parent_guid(self) -> str | None:
if "parent" not in self.properties_json:
return None
task_model: TaskModel = self.__class__.query.filter_by(guid=self.properties_json["parent"]).first()
parent_guid: str = self.properties_json["parent"]
return parent_guid
def parent_task_model(self) -> TaskModel | None:
task_model: TaskModel = self.__class__.query.filter_by(guid=self.parent_guid()).first()
return task_model
@classmethod

View File

@ -688,10 +688,25 @@ class ProcessInstanceProcessor:
json_data_hashes = set()
states_to_exclude_from_rehydration: list[str] = []
if not include_task_data_for_completed_tasks:
states_to_exclude_from_rehydration = ["COMPLETED", "CANCELLED", "ERROR"]
# load CANCELLED task data for Gateways since they are marked as CANCELLED
# and we need the task data from their parents
states_to_exclude_from_rehydration = ["COMPLETED", "ERROR"]
task_list_by_hash = {t.guid: t for t in tasks}
parent_task_guids = []
for task in tasks:
if task.state not in states_to_exclude_from_rehydration:
json_data_hashes.add(task.json_data_hash)
# load parent task data to avoid certain issues that can arise from parallel branches
parent_guid = task.parent_guid()
if (
parent_guid in task_list_by_hash
and task_list_by_hash[parent_guid].state in states_to_exclude_from_rehydration
):
json_data_hashes.add(task_list_by_hash[parent_guid].json_data_hash)
parent_task_guids.append(parent_guid)
json_data_records = JsonDataModel.query.filter(JsonDataModel.hash.in_(json_data_hashes)).all() # type: ignore
json_data_mappings = {}
for json_data_record in json_data_records:
@ -703,7 +718,7 @@ class ProcessInstanceProcessor:
tasks_dict = spiff_bpmn_process_dict["subprocesses"][bpmn_subprocess_guid]["tasks"]
tasks_dict[task.guid] = task.properties_json
task_data = {}
if task.state not in states_to_exclude_from_rehydration:
if task.state not in states_to_exclude_from_rehydration or task.guid in parent_task_guids:
task_data = json_data_mappings[task.json_data_hash]
tasks_dict[task.guid]["data"] = task_data