# Buggy code
def set_step_outputs(self, invocation_step, outputs, already_persisted=False):
    step = invocation_step.workflow_step
    if invocation_step.output_value:
        outputs[invocation_step.output_value.workflow_output.output_name] = (
            invocation_step.output_value.value
        )
    self.outputs[step.id] = outputs
    if not already_persisted:
        for output_name, output_object in outputs.items():
            if hasattr(output_object, "history_content_type"):
                invocation_step.add_output(output_name, output_object)
            else:
                # This is a problem, this non-data, non-collection output
                # won't be recovered on a subsequent workflow scheduling
                # iteration. This seems to have been a pre-existing problem
                # prior to #4584 though.
                pass
        for workflow_output in step.workflow_outputs:
            output_name = workflow_output.output_name
            if output_name not in outputs:
                message = "Failed to find expected workflow output [{}] in step outputs [{}]".format(
                    output_name, outputs
                )
                # raise KeyError(message)
                # Pre-18.01 we would have never even detected this output wasn't configured
                # and even in 18.01 we don't have a way to tell the user something bad is
                # happening so I guess we just log a debug message and continue sadly for now.
                # Once https://github.com/galaxyproject/galaxy/issues/5142 is complete we could
                # at least tell the user what happened, give them a warning.
                log.debug(message)
                continue
            output = outputs[output_name]
            self._record_workflow_output(
                step,
                workflow_output,
                output=output,
            )


# 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 set_step_outputs(self, invocation_step, outputs, already_persisted=False):
    step = invocation_step.workflow_step
    if invocation_step.output_value:
        outputs[invocation_step.output_value.workflow_output.output_name] = (
            invocation_step.output_value.value
        )
    self.outputs[step.id] = outputs
    if not already_persisted:
        for workflow_output in step.workflow_outputs:
            output_name = workflow_output.output_name
            if output_name not in outputs:
                message = "Failed to find expected workflow output [{}] in step outputs [{}]".format(
                    output_name, outputs
                )
                # raise KeyError(message)
                # Pre-18.01 we would have never even detected this output wasn't configured
                # and even in 18.01 we don't have a way to tell the user something bad is
                # happening so I guess we just log a debug message and continue sadly for now.
                # Once https://github.com/galaxyproject/galaxy/issues/5142 is complete we could
                # at least tell the user what happened, give them a warning.
                log.debug(message)
                continue
            output = outputs[output_name]
            self._record_workflow_output(
                step,
                workflow_output,
                output=output,
            )