# Buggy code
def record_success(self, execution_slice, job, outputs):
    super().record_success(execution_slice, job, outputs)
    if not self.collection_info:
        self.invocation_step.job = job


# Traceback (KeyError)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: galaxy.workflow.run ERROR 2020-12-18 11:53:28,997 Failed to schedule Workflow[id=74152,name=COVID-19: variation analysis reporting v2], problem occurred on WorkflowStep[index=25,type=tool].
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Traceback (most recent call last):
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 353, in replacement_for_connection
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: replacement = step_outputs[output_name]
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: KeyError: 'out_file1'
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: During handling of the above exception, another exception occurred:
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Traceback (most recent call last):
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 190, in invoke
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: incomplete_or_none = self._invoke_step(workflow_invocation_step)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 266, in _invoke_step
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: use_cached_job=self.workflow_invocation.use_cached_job)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 1666, in execute
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: collection_info = self.compute_collection_info(progress, step, all_inputs)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 336, in compute_collection_info
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: progress, step, all_inputs
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 354, in _find_collections_to_match
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: data = progress.replacement_for_input(step, input_dict)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 337, in replacement_for_input
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: replacement = self.replacement_for_connection(connection[0], is_data=is_data)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 358, in replacement_for_connection
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: raise Exception(message)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Exception: Workflow evaluation problem - failed to find output_name out_file1 in step_outputs {}
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: galaxy.workflow.run ERROR 2020-12-18 11:53:29,002 Failed to execute scheduled workflow.
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Traceback (most recent call last):
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 353, in replacement_for_connection
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: replacement = step_outputs[output_name]
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: KeyError: 'out_file1'
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: During handling of the above exception, another exception occurred:
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Traceback (most recent call last):
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 83, in __invoke
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: outputs = invoker.invoke()
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 190, in invoke
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: incomplete_or_none = self._invoke_step(workflow_invocation_step)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 266, in _invoke_step
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: use_cached_job=self.workflow_invocation.use_cached_job)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 1666, in execute
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: collection_info = self.compute_collection_info(progress, step, all_inputs)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 336, in compute_collection_info
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: progress, step, all_inputs
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/modules.py", line 354, in _find_collections_to_match
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: data = progress.replacement_for_input(step, input_dict)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 337, in replacement_for_input
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: replacement = self.replacement_for_connection(connection[0], is_data=is_data)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: File "/opt/galaxy/server/lib/galaxy/workflow/run.py", line 358, in replacement_for_connection
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: raise Exception(message)
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: Exception: Workflow evaluation problem - failed to find output_name out_file1 in step_outputs {}
Dec 18 11:53:29 sn04.bi.uni-freiburg.de python[2113691]: galaxy.workflow.scheduling_manager DEBUG 2020-12-18 11:53:29,021 Workflow invocation [129864] scheduled


# Fixed code
def record_success(self, execution_slice, job, outputs):
    super().record_success(execution_slice, job, outputs)
    if not self.collection_info:
        for output_name, output in outputs:
            self.invocation_step.add_output(output_name, output)
        self.invocation_step.job = job