Fix hda_manager.copy so it doesn't flush datasets without a history_id

This commit is contained in:
mvdbeek
2021-10-18 11:42:40 +02:00
parent bf7cc9072c
commit 53e3cf56c3
2 changed files with 10 additions and 10 deletions
+3 -1
View File
@@ -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):
+7 -9
View File
@@ -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