# Buggy code
def set_step_outputs(self, invocation_step, outputs, already_persisted=False):
    step = invocation_step.workflow_step
    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 [%s] in step outputs [%s]"
                    % (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 (Exception)
[pid: 63775|app: 0|req: 160/596] 127.0.0.1 () {50 vars in 1324 bytes} [Wed Jul 31 09:38:45 2019] GET /api/histories/1cd8e2f6b131e891/contents?details=3f5830403180d620&amp;order=hid&amp;v=dev&amp;q=update_time-ge&amp;q=deleted&amp;q=purged&amp;qv=2019-07-31T16%3A38%3A41.000Z&amp;qv=False&amp;qv=False => generated 2 bytes in 53 msecs (HTTP/1.1 200) 3 headers in 139 bytes (1 switches on core 3)
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:45,835 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Attempting to schedule workflow invocation [(4,)]
galaxy.workflow.run DEBUG 2019-07-31 09:38:45,941 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 10 outputs of invocation 4 delayed (tool [__BUILD_LIST__] inputs are not ready, this special tool requires inputs to be ready)
galaxy.workflow.run DEBUG 2019-07-31 09:38:45,941 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 11 outputs of invocation 4 delayed (dependent step [10] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:45,941 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 12 outputs of invocation 4 delayed (dependent step [11] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:45,942 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 13 outputs of invocation 4 delayed (dependent step [11] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:45,942 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 14 outputs of invocation 4 delayed (dependent step [13] delayed, so this step must be delayed)
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:45,957 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Workflow invocation [4] scheduled
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:46,960 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Attempting to schedule workflow invocation [(4,)]
galaxy.workflow.run DEBUG 2019-07-31 09:38:47,070 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 10 outputs of invocation 4 delayed (tool [__BUILD_LIST__] inputs are not ready, this special tool requires inputs to be ready)
galaxy.workflow.run DEBUG 2019-07-31 09:38:47,071 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 11 outputs of invocation 4 delayed (dependent step [10] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:47,071 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 12 outputs of invocation 4 delayed (dependent step [11] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:47,072 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 13 outputs of invocation 4 delayed (dependent step [11] delayed, so this step must be delayed)
galaxy.workflow.run DEBUG 2019-07-31 09:38:47,072 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Marking step 14 outputs of invocation 4 delayed (dependent step [13] delayed, so this step must be delayed)
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:47,086 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Workflow invocation [4] scheduled
galaxy.jobs.runners.drmaa DEBUG 2019-07-31 09:38:47,465 [p:63775,w:2,m:0] [SlurmRunner.monitor_thread] (10/24674328) state change: job finished normally
galaxy.model.metadata DEBUG 2019-07-31 09:38:47,587 [p:63775,w:2,m:0] [SlurmRunner.work_thread-0] loading metadata from file for: HistoryDatasetAssociation 16
galaxy.jobs INFO 2019-07-31 09:38:47,692 [p:63775,w:2,m:0] [SlurmRunner.work_thread-0] Collecting metrics for Job 10 in /project/6004808/ncm3/galaxy-19.05-git/galaxy-database/jobs_directory/000/10
galaxy.jobs DEBUG 2019-07-31 09:38:47,703 [p:63775,w:2,m:0] [SlurmRunner.work_thread-0] job 10 ended (finish() executed in (159.904 ms))
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:48,090 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Attempting to schedule workflow invocation [(4,)]
galaxy.managers.collections DEBUG 2019-07-31 09:38:48,247 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Created collection with 2 elements
/project/6004808/ncm3/galaxy-19.05-git/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py:268: SAWarning: Unicode type received non-unicode bind param value 'list'. (this warning may be suppressed after 10 occurrences)
(util.ellipses_string(value),),
/project/6004808/ncm3/galaxy-19.05-git/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py:268: SAWarning: Unicode type received non-unicode bind param value 'output'. (this warning may be suppressed after 10 occurrences)
(util.ellipses_string(value),),
galaxy.tools.actions.model_operations INFO 2019-07-31 09:38:48,343 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Calling produce_outputs, tool is <galaxy.tools.BuildListCollectionTool object at 0x7f32a9f2a690>
galaxy.tools.execute DEBUG 2019-07-31 09:38:48,348 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Tool [__BUILD_LIST__] created job [11] (153.141 ms)
galaxy.tools.execute DEBUG 2019-07-31 09:38:48,358 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Executed 1 job(s) for tool __BUILD_LIST__ request: (178.532 ms)
galaxy.workflow.run DEBUG 2019-07-31 09:38:48,368 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Workflow step 10 of invocation 4 invoked (189.270 ms)
galaxy.managers.collections DEBUG 2019-07-31 09:38:48,441 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Created collection with 0 elements
galaxy.managers.collections DEBUG 2019-07-31 09:38:48,469 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Created collection with 2 elements
/project/6004808/ncm3/galaxy-19.05-git/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py:268: SAWarning: Unicode type received non-unicode bind param value 'input'. (this warning may be suppressed after 10 occurrences)
(util.ellipses_string(value),),
/project/6004808/ncm3/galaxy-19.05-git/galaxy/.venv/lib/python2.7/site-packages/sqlalchemy/sql/sqltypes.py:268: SAWarning: Unicode type received non-unicode bind param value 'output_discarded'. (this warning may be suppressed after 10 occurrences)
(util.ellipses_string(value),),
galaxy.tools.actions.model_operations INFO 2019-07-31 09:38:48,512 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Calling produce_outputs, tool is <galaxy.tools.FilterFromFileTool object at 0x7f32a9f63810>
galaxy.tools.execute DEBUG 2019-07-31 09:38:48,516 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Tool [__FILTER_FROM_FILE__] created job [12] (106.710 ms)
galaxy.tools.execute DEBUG 2019-07-31 09:38:48,524 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Executed 1 job(s) for tool __FILTER_FROM_FILE__ request: (140.242 ms)
galaxy.workflow.run DEBUG 2019-07-31 09:38:48,533 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Workflow step 11 of invocation 4 invoked (164.122 ms)
galaxy.workflow.run ERROR 2019-07-31 09:38:48,553 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Failed to schedule Workflow[id=2,name=test merge empty (imported from uploaded file)], problem occurred on WorkflowStep[index=4,type=tool].
Traceback (most recent call last):
File "lib/galaxy/workflow/run.py", line 190, in invoke
incomplete_or_none = self._invoke_step(workflow_invocation_step)
File "lib/galaxy/workflow/run.py", line 266, in _invoke_step
use_cached_job=self.workflow_invocation.use_cached_job)
File "lib/galaxy/workflow/modules.py", line 1189, in execute
collection_info = self.compute_collection_info(progress, step, all_inputs)
File "lib/galaxy/workflow/modules.py", line 309, in compute_collection_info
progress, step, all_inputs
File "lib/galaxy/workflow/modules.py", line 327, in _find_collections_to_match
data = progress.replacement_for_input(step, input_dict)
File "lib/galaxy/workflow/run.py", line 337, in replacement_for_input
replacement = self.replacement_for_connection(connection[0], is_data=is_data)
File "lib/galaxy/workflow/run.py", line 358, in replacement_for_connection
raise Exception(message)
Exception: Workflow evaluation problem - failed to find output_name output in step_outputs {}
galaxy.workflow.run ERROR 2019-07-31 09:38:48,697 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Failed to execute scheduled workflow.
Traceback (most recent call last):
File "lib/galaxy/workflow/run.py", line 83, in __invoke
outputs = invoker.invoke()
File "lib/galaxy/workflow/run.py", line 190, in invoke
incomplete_or_none = self._invoke_step(workflow_invocation_step)
File "lib/galaxy/workflow/run.py", line 266, in _invoke_step
use_cached_job=self.workflow_invocation.use_cached_job)
File "lib/galaxy/workflow/modules.py", line 1189, in execute
collection_info = self.compute_collection_info(progress, step, all_inputs)
File "lib/galaxy/workflow/modules.py", line 309, in compute_collection_info
progress, step, all_inputs
File "lib/galaxy/workflow/modules.py", line 327, in _find_collections_to_match
data = progress.replacement_for_input(step, input_dict)
File "lib/galaxy/workflow/run.py", line 337, in replacement_for_input
replacement = self.replacement_for_connection(connection[0], is_data=is_data)
File "lib/galaxy/workflow/run.py", line 358, in replacement_for_connection
raise Exception(message)
Exception: Workflow evaluation problem - failed to find output_name output in step_outputs {}
galaxy.workflow.scheduling_manager DEBUG 2019-07-31 09:38:48,712 [p:63775,w:2,m:0] [WorkflowRequestMonitor.monitor_thread] Workflow invocation [4] 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 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 [%s] in step outputs [%s]"
                    % (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,
            )