From 2950ae6ab9bd7f98f56c3dba2ec7796eed16ec84 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 13 May 2024 16:01:38 +0200 Subject: [PATCH 1/2] Fix addition of default collection to history --- lib/galaxy/tools/parameters/basic.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 62b29613d1fe..61cb868854d6 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -2737,6 +2737,7 @@ def raw_to_galaxy(trans, as_dict_value): name=name, collection=collection, ) + app.model.session.add(hdca) def write_elements_to_collection(has_elements, collection_builder): element_dicts = has_elements.get("elements") @@ -2753,8 +2754,9 @@ def write_elements_to_collection(has_elements, collection_builder): collection_builder = builder.BoundCollectionBuilder(collection) write_elements_to_collection(as_dict_value, collection_builder) collection_builder.populate() - trans.sa_session.add(hdca) - trans.sa_session.flush() + history.stage_addition(hdca) + history.add_pending_items() + app.model.session.flush() return hdca From 25f8d7ec1d86dba2c16e0ade2f185fa9730090aa Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Tue, 14 May 2024 10:31:42 +0200 Subject: [PATCH 2/2] Don't flush for inner elements --- lib/galaxy/tools/parameters/basic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 61cb868854d6..dbe1b065a243 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -2675,7 +2675,7 @@ def to_text(self, value): # Code from CWL branch to massage in order to be shared across tools and workflows, # and for CWL artifacts as well as Galaxy ones. -def raw_to_galaxy(trans, as_dict_value): +def raw_to_galaxy(trans, as_dict_value, commit=True): app = trans.app history = trans.history @@ -2725,7 +2725,8 @@ def raw_to_galaxy(trans, as_dict_value): trans.sa_session.add(primary_data) history.stage_addition(primary_data) history.add_pending_items() - trans.sa_session.flush() + if commit: + app.model.session.commit() return primary_data else: name = as_dict_value.get("name") @@ -2745,7 +2746,8 @@ def write_elements_to_collection(has_elements, collection_builder): element_class = element_dict["class"] identifier = element_dict["identifier"] if element_class == "File": - hda = raw_to_galaxy(trans, element_dict) + # Don't commit for inner elements + hda = raw_to_galaxy(trans, element_dict, commit=False) collection_builder.add_dataset(identifier, hda) else: subcollection_builder = collection_builder.get_level(identifier) @@ -2756,7 +2758,8 @@ def write_elements_to_collection(has_elements, collection_builder): collection_builder.populate() history.stage_addition(hdca) history.add_pending_items() - app.model.session.flush() + if commit: + app.model.session.commit() return hdca