Skip to content

Commit

Permalink
WorkflowSummary: add dict to map a job id to its representative job
Browse files Browse the repository at this point in the history
Fix #2742 introduced in commit 9ede8e5 .

The representative job is the first in the returned query, so substantially
random and not necessarily the one with the lowest job id.
Mapping a job id to its representative job in extract_steps() makes it
robust also against API requests with manually chosen collection job ids.
  • Loading branch information
nsoranzo committed Oct 12, 2016
1 parent dcde64c commit 04bf215
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/galaxy/workflow/extract.py
Expand Up @@ -102,12 +102,11 @@ def extract_steps( trans, history=None, job_ids=None, dataset_ids=None, dataset_
hid_to_output_pair[ hid ] = ( step, 'output' )
steps.append( step )
# Tool steps
jobs_by_id = dict( ( job.id, job ) for job in jobs.keys() )
for job_id in job_ids:
if job_id not in jobs_by_id:
log.warning( "job_id %s not found in jobs_by_id %s" % ( job_id, jobs_by_id ) )
if job_id not in summary.job_id2representative_job:
log.warning( "job_id %s not found in job_id2representative_job %s" % ( job_id, summary.job_id2representative_job ) )
raise AssertionError( "Attempt to create workflow with job not connected to current history" )
job = jobs_by_id[ job_id ]
job = summary.job_id2representative_job[job_id]
tool_inputs, associations = step_inputs( trans, job )
step = model.WorkflowStep()
step.type = 'tool'
Expand Down Expand Up @@ -201,6 +200,7 @@ def __init__( self, trans, history ):
self.history = history
self.warnings = set()
self.jobs = odict()
self.job_id2representative_job = {} # map a non-fake job id to its representative job
self.implicit_map_jobs = []
self.collection_types = {}

Expand Down Expand Up @@ -237,6 +237,9 @@ def __summarize_dataset_collection( self, dataset_collection ):
self.implicit_map_jobs.append( representative_job )
else:
self.jobs[ representative_job ].append( ( representative_assoc.name, dataset_collection ) )
for assoc in cja:
job = assoc.job
self.job_id2representative_job[job.id] = representative_job
# This whole elif condition may no longer be needed do to additional
# tracking with creating_job_associations. Will delete at some point.
elif dataset_collection.implicit_output_name:
Expand All @@ -257,6 +260,7 @@ def __summarize_dataset_collection( self, dataset_collection ):
job = assoc.job
if job not in self.jobs or self.jobs[ job ][ 0 ][ 1 ].history_content_type == "dataset":
self.jobs[ job ] = [ ( assoc.name, dataset_collection ) ]
self.job_id2representative_job[job.id] = job
self.implicit_map_jobs.append( job )
else:
self.jobs[ job ].append( ( assoc.name, dataset_collection ) )
Expand All @@ -279,6 +283,7 @@ def __summarize_dataset( self, dataset ):
self.jobs[ job ].append( ( assoc.name, dataset ) )
else:
self.jobs[ job ] = [ ( assoc.name, dataset ) ]
self.job_id2representative_job[job.id] = job

def __original_hdca( self, hdca ):
while hdca.copied_from_history_dataset_collection_association:
Expand Down

0 comments on commit 04bf215

Please sign in to comment.