diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index f77d264b..2f4299a8 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -242,13 +242,15 @@ class WorkflowService(object): @staticmethod def get_previously_submitted_data(workflow_id, task): """ If the user has completed this task previously, find the form data for the last submission.""" - mi_index = task.multi_instance_index if hasattr(task, 'multi_instance_index') else None; - latest_event = db.session.query(TaskEventModel) \ + query = db.session.query(TaskEventModel) \ .filter_by(workflow_id=workflow_id) \ .filter_by(task_name=task.task_spec.name) \ - .filter_by(action=WorkflowService.TASK_ACTION_COMPLETE) \ - .filter_by(mi_index=mi_index) \ - .order_by(TaskEventModel.date.desc()).first() + .filter_by(action=WorkflowService.TASK_ACTION_COMPLETE) + + if hasattr(task, 'multi_instance_index'): + query = query.filter_by(mi_index=task.multi_instance_index) + + latest_event = query.order_by(TaskEventModel.date.desc()).first() if latest_event: if latest_event.form_data is not None: return latest_event.form_data