Skip to content

Commit 79b26d2

Browse files
committed
Fix collection operations not having a history.
Fixes #3437.
1 parent a5b0e76 commit 79b26d2

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

lib/galaxy/tools/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,8 @@ def produce_outputs( self, trans, out_data, output_collections, incoming, histor
23522352
new_elements = odict()
23532353
new_elements["forward"] = forward
23542354
new_elements["reverse"] = reverse
2355+
history.add_dataset( forward, set_hid=False )
2356+
history.add_dataset( reverse, set_hid=False )
23552357

23562358
output_collections.create_collection(
23572359
next(iter(self.outputs.values())), "output", elements=new_elements
@@ -2430,7 +2432,10 @@ def produce_outputs( self, trans, out_data, output_collections, incoming, histor
24302432
# Don't copy until we know everything is fine and we have the structure of the list ready to go.
24312433
new_elements = odict()
24322434
for key, value in new_element_structure.items():
2433-
new_elements[key] = value.copy()
2435+
copied_value = value.copy()
2436+
if getattr(copied_value, "history_content_type", None) == "dataset":
2437+
history.add_dataset(copied_value, set_hid=False)
2438+
new_elements[key] = copied_value
24342439

24352440
output_collections.create_collection(
24362441
next(iter(self.outputs.values())), "output", elements=new_elements
@@ -2465,7 +2470,10 @@ def produce_outputs( self, trans, out_data, output_collections, incoming, histor
24652470

24662471
if valid:
24672472
element_identifier = dce.element_identifier
2468-
new_elements[element_identifier] = element.copy()
2473+
copied_value = element.copy()
2474+
if getattr(copied_value, "history_content_type", None) == "dataset":
2475+
history.add_dataset(copied_value, set_hid=False)
2476+
new_elements[element_identifier] = copied_value
24692477

24702478
output_collections.create_collection(
24712479
next(iter(self.outputs.values())), "output", elements=new_elements
@@ -2488,8 +2496,9 @@ def add_elements(collection, prefix=""):
24882496
if dce.is_collection:
24892497
add_elements(dce_object, prefix=identifier)
24902498
else:
2491-
new_elements[identifier] = dce_object.copy()
2492-
2499+
copied_dataset = dce_object.copy()
2500+
history.add_dataset(copied_dataset, set_hid=False)
2501+
new_elements[identifier] = copied_dataset
24932502
add_elements(hdca.collection)
24942503
output_collections.create_collection(
24952504
next(iter(self.outputs.values())), "output", elements=new_elements

lib/galaxy/tools/actions/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,17 @@ def create_collection(self, output, name, **element_kwds):
679679

680680
collection_type = input_collections[collection_type_source].collection.collection_type
681681

682+
if "elements" in element_kwds:
683+
elements = element_kwds["elements"]
684+
if hasattr(elements, "items"): # else it is ELEMENTS_UNINITIALIZED object.
685+
for key, value in elements.items():
686+
# Either a HDA (if) or a DatasetCollection (the else)
687+
if getattr(value, "history_content_type", None) == "dataset":
688+
assert value.history is not None
689+
else:
690+
for dataset in value.dataset_instances:
691+
assert dataset.history is not None
692+
682693
if self.mapping_over_collection:
683694
dc = collections_manager.create_dataset_collection(
684695
self.trans,

test/api/test_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def test_zip_inputs( self ):
166166
response = self._run( "__ZIP_COLLECTION__", history_id, inputs, assert_ok=True )
167167
output_collections = response[ "output_collections" ]
168168
self.assertEquals( len(output_collections), 1 )
169+
self.dataset_populator.wait_for_job( response["jobs"][0]["id"], assert_ok=True )
170+
zipped_hdca = self.dataset_populator.get_history_collection_details(history_id, hid=output_collections[0]["hid"])
171+
assert zipped_hdca["collection_type"] == "paired"
169172

170173
def test_zip_list_inputs( self ):
171174
history_id = self.dataset_populator.new_history()
@@ -179,6 +182,9 @@ def test_zip_list_inputs( self ):
179182
response = self._run( "__ZIP_COLLECTION__", history_id, inputs, assert_ok=True )
180183
implicit_collections = response[ "implicit_collections" ]
181184
self.assertEquals( len(implicit_collections), 1 )
185+
self.dataset_populator.wait_for_job( response["jobs"][0]["id"], assert_ok=True )
186+
zipped_hdca = self.dataset_populator.get_history_collection_details(history_id, hid=implicit_collections[0]["hid"])
187+
assert zipped_hdca["collection_type"] == "list:paired"
182188

183189
def test_filter_failed( self ):
184190
history_id = self.dataset_populator.new_history()

test/base/populators.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,23 @@ def __history_content_id( self, history_id, wait=True, **kwds ):
173173
# kwds should contain a 'dataset' object response, a 'dataset_id' or
174174
# the last dataset in the history will be fetched.
175175
if "dataset_id" in kwds:
176-
dataset_id = kwds[ "dataset_id" ]
176+
history_content_id = kwds[ "dataset_id" ]
177177
elif "dataset" in kwds:
178-
dataset_id = kwds[ "dataset" ][ "id" ]
178+
history_content_id = kwds[ "dataset" ][ "id" ]
179179
else:
180180
hid = kwds.get( "hid", None ) # If not hid, just grab last dataset
181+
history_contents = self.__get_contents_request( history_id ).json()
181182
if hid:
182-
index = hid - 1
183+
history_content_id = None
184+
for history_item in history_contents:
185+
if history_item["hid"] == hid:
186+
history_content_id = history_item["id"]
187+
if history_content_id is None:
188+
raise Exception("Could not find content with HID [%s] in [%s]" % (hid, history_contents))
183189
else:
184190
# No hid specified - just grab most recent element.
185-
index = -1
186-
dataset_contents = self.__get_contents_request( history_id ).json()
187-
dataset_id = dataset_contents[ index ][ "id" ]
188-
return dataset_id
191+
history_content_id = history_contents[-1]["id"]
192+
return history_content_id
189193

190194
def __get_contents_request( self, history_id, suffix=""):
191195
url = "histories/%s/contents" % history_id

0 commit comments

Comments
 (0)