From 53e3cf56c3eeea5ee27583476cfc38e12ccbd962 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 15 Oct 2021 15:51:00 +0200 Subject: [PATCH] Fix hda_manager.copy so it doesn't flush datasets without a history_id --- lib/galaxy/managers/collections.py | 4 +++- lib/galaxy/managers/hdas.py | 16 +++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index 93ff9b3246b..57a06b41313 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -201,6 +201,7 @@ class DatasetCollectionManager: has_subcollections = collection_type_description.has_subcollections() # If we have elements, this is an internal request, don't need to load # objects from identifiers. + history = history or trans.history if elements is None: elements = self._element_identifiers_to_elements(trans, collection_type_description=collection_type_description, @@ -208,6 +209,7 @@ class DatasetCollectionManager: hide_source_items=hide_source_items, copy_elements=copy_elements, history=history) + history.add_pending_items() else: if has_subcollections: # Nested collection - recursively create collections as needed. @@ -493,7 +495,7 @@ class DatasetCollectionManager: decoded_id = int(trans.app.security.decode_id(encoded_id)) hda = self.hda_manager.get_accessible(decoded_id, trans.user) if copy_elements: - element = self.hda_manager.copy(hda, history=history or trans.history, hide_copy=True) + element = self.hda_manager.copy(hda, history=history or trans.history, hide_copy=True, flush=False) else: element = hda if hide_source_items and self.hda_manager.get_owned(hda.id, user=trans.user, current_history=history or trans.history): diff --git a/lib/galaxy/managers/hdas.py b/lib/galaxy/managers/hdas.py index 6662c154300..1105dc24f4c 100644 --- a/lib/galaxy/managers/hdas.py +++ b/lib/galaxy/managers/hdas.py @@ -8,6 +8,8 @@ import gettext import logging import os +from sqlalchemy.orm.session import object_session + from galaxy import ( datatypes, exceptions, @@ -110,26 +112,22 @@ class HDAManager(datasets.DatasetAssociationManager, self.session().flush() return hda - def copy(self, hda, history=None, hide_copy=False, **kwargs): + def copy(self, hda, history=None, hide_copy=False, flush=True, **kwargs): """ Copy hda, including annotation and tags, add to history and return the given HDA. """ - copy = hda.copy(parent_id=kwargs.get('parent_id'), copy_hid=False) + copy = hda.copy(parent_id=kwargs.get('parent_id'), copy_hid=False, copy_tags=hda.tags) if hide_copy: copy.visible = False - # add_dataset will update the hid to the next avail. in history if history: - history.add_dataset(copy) + history.stage_addition(copy) - copy.copied_from_history_dataset_association = hda copy.set_size() original_annotation = self.annotation(hda) self.annotate(copy, original_annotation, user=hda.history.user) - - # these use a session flush - original_tags = self.get_tags(hda) - self.set_tags(copy, original_tags, user=hda.history.user) + if flush: + object_session(copy).flush() return copy