Merge pull request #17777 from mvdbeek/fix_copy_of_hda_not_getting_metadata

[24.0] Also set extension and metadata on copies of job outputs when finishing job
This commit is contained in:
Marius van den Beek
2024-03-19 19:53:03 +01:00
committed by GitHub
5 changed files with 49 additions and 10 deletions
+8 -3
View File
@@ -67,6 +67,7 @@ from galaxy.model import (
Task,
)
from galaxy.model.base import transaction
from galaxy.model.store import copy_dataset_instance_metadata_attributes
from galaxy.model.store.discover import MaxDiscoveredFilesExceededError
from galaxy.objectstore import ObjectStorePopulator
from galaxy.structured_app import MinimalManagerApp
@@ -1949,9 +1950,7 @@ class MinimalJobWrapper(HasResourceParameters):
]
for dataset_assoc in output_dataset_associations:
if getattr(dataset_assoc.dataset, "discovered", False):
# skip outputs that have been discovered
continue
is_discovered_dataset = getattr(dataset_assoc.dataset, "discovered", False)
context = self.get_dataset_finish_context(job_context, dataset_assoc)
# should this also be checking library associations? - can a library item be added from a history before the job has ended? -
# lets not allow this to occur
@@ -1960,6 +1959,12 @@ class MinimalJobWrapper(HasResourceParameters):
dataset_assoc.dataset.dataset.history_associations
+ dataset_assoc.dataset.dataset.library_associations
):
if is_discovered_dataset:
if dataset is dataset_assoc.dataset:
continue
elif dataset.extension == dataset_assoc.dataset.extension or dataset.extension == "auto":
copy_dataset_instance_metadata_attributes(dataset_assoc.dataset, dataset)
continue
output_name = dataset_assoc.name
# Handles retry internally on error for instance...
+13 -5
View File
@@ -478,12 +478,11 @@ class ModelImportStore(metaclass=abc.ABCMeta):
if (
dataset_association is not dataset_instance
and dataset_association.extension == dataset_instance.extension
or dataset_association.extension == "auto"
):
dataset_association.metadata = dataset_instance.metadata
dataset_association.blurb = dataset_instance.blurb
dataset_association.peek = dataset_instance.peek
dataset_association.info = dataset_instance.info
dataset_association.tool_version = dataset_instance.tool_version
copy_dataset_instance_metadata_attributes(
source=dataset_instance, target=dataset_association
)
if job:
dataset_instance.dataset.job_id = job.id
@@ -3085,3 +3084,12 @@ def payload_to_source_uri(payload) -> str:
dump(store_dict, f)
source_uri = f"file://{import_json}"
return source_uri
def copy_dataset_instance_metadata_attributes(source: model.DatasetInstance, target: model.DatasetInstance) -> None:
target.metadata = source.metadata
target.blurb = source.blurb
target.peek = source.peek
target.info = source.info
target.tool_version = source.tool_version
target.extension = source.extension
+1 -1
View File
@@ -2875,7 +2875,7 @@ class ExpressionTool(Tool):
break
if copy_object is None:
raise exceptions.MessageException("Failed to find dataset output.")
out_data[key].copy_from(copy_object)
out_data[key].copy_from(copy_object, include_metadata=True)
def parse_environment_variables(self, tool_source):
"""Setup environment variable for inputs file."""
+12 -1
View File
@@ -2006,7 +2006,7 @@ test_data:
# Makes sure that setting metadata on expression tool data outputs
# doesn't break result evaluation.
with self.dataset_populator.test_history() as history_id:
self._run_workflow(
summary = self._run_workflow(
"""class: GalaxyWorkflow
inputs:
some_file:
@@ -2031,6 +2031,9 @@ steps:
- __index__: 0
value:
__class__: RuntimeValue
outputs:
pick_out:
outputSource: pick_value/data_param
""",
test_data="""
some_file:
@@ -2040,6 +2043,14 @@ some_file:
""",
history_id=history_id,
)
invocation_details = self.workflow_populator.get_invocation(summary.invocation_id, step_details=True)
# Make sure metadata is actually available
pick_value_hda = invocation_details["outputs"]["pick_out"]
dataset_details = self.dataset_populator.get_history_dataset_details(
history_id=history_id, content_id=pick_value_hda["id"]
)
assert dataset_details["metadata_reference_names"]
assert dataset_details["metadata_bam_index"]
def test_run_workflow_simple_conditional_step(self):
with self.dataset_populator.test_history() as history_id:
+15
View File
@@ -827,6 +827,21 @@ def test_sessionless_import_edit_datasets():
assert d2 is not None
def test_import_job_with_output_copy():
app, h, temp_directory, import_history = _setup_simple_export({"for_edit": True})
hda = h.active_datasets[-1]
# Simulate a copy being made of an output hda
copy = hda.copy(new_name="output copy")
# set extension to auto, should be changed to real extension when finalizing job
copy.extension = "auto"
app.add_and_commit(copy)
import_model_store = store.get_import_model_store_for_directory(
temp_directory, import_options=store.ImportOptions(allow_dataset_object_edit=True, allow_edit=True), app=app
)
import_model_store.perform_import()
assert copy.extension == "txt"
def test_import_datasets_with_ids_fails_if_not_editing_models():
app, h, temp_directory, import_history = _setup_simple_export({"for_edit": True})
u = h.user