Skip to content

Commit

Permalink
Split raw_to_galaxy() trans requirement to app and history
Browse files Browse the repository at this point in the history
Marginal improvement, but might be nice not to be bound to
`trans.history`.

Co-authored-by: Marius van den Beek <[email protected]>
  • Loading branch information
nsoranzo and mvdbeek committed Mar 7, 2024
1 parent 833ad06 commit 1e95836
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
26 changes: 14 additions & 12 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@
if TYPE_CHECKING:
from sqlalchemy.orm import Session

from galaxy.model import (
History,
HistoryItem,
)
from galaxy.security.idencoding import IdEncodingHelper
from galaxy.structured_app import MinimalApp

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -2116,7 +2121,7 @@ def from_json(self, value, trans, other_values=None):
raise ParameterValueError("specify a dataset of the required format / build for parameter", self.name)
if value in [None, "None", ""]:
if self.default_object:
return raw_to_galaxy(trans, self.default_object)
return raw_to_galaxy(trans.app, trans.history, self.default_object)
return None
if isinstance(value, MutableMapping) and "values" in value:
value = self.to_python(value, trans.app)
Expand Down Expand Up @@ -2456,7 +2461,7 @@ def from_json(self, value, trans, other_values=None):
raise ParameterValueError("specify a dataset collection of the correct type", self.name)
if value in [None, "None"]:
if self.default_object:
return raw_to_galaxy(trans, self.default_object)
return raw_to_galaxy(trans.app, trans.history, self.default_object)
return None
if isinstance(value, MutableMapping) and "values" in value:
value = self.to_python(value, trans.app)
Expand Down Expand Up @@ -2672,10 +2677,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):
app = trans.app
history = trans.history

def raw_to_galaxy(app: "MinimalApp", history: "History", as_dict_value: Dict[str, Any]) -> "HistoryItem":
object_class = as_dict_value["class"]
if object_class == "File":
# TODO: relative_to = "/"
Expand Down Expand Up @@ -2714,15 +2716,15 @@ def raw_to_galaxy(trans, as_dict_value):
dbkey="?",
dataset=dataset,
flush=False,
sa_session=trans.sa_session,
sa_session=app.model.session,
)
primary_data.state = Dataset.states.DEFERRED
permissions = app.security_agent.history_get_default_permissions(history)
app.security_agent.set_all_dataset_permissions(primary_data.dataset, permissions, new=True, flush=False)
trans.sa_session.add(primary_data)
app.model.session.add(primary_data)
history.stage_addition(primary_data)
history.add_pending_items()
trans.sa_session.flush()
app.model.session.flush()
return primary_data
else:
name = as_dict_value.get("name")
Expand All @@ -2741,7 +2743,7 @@ 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)
hda = raw_to_galaxy(app, history, element_dict)
collection_builder.add_dataset(identifier, hda)
else:
subcollection_builder = collection_builder.get_level(identifier)
Expand All @@ -2750,8 +2752,8 @@ 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()
app.model.session.add(hdca)
app.model.session.flush()
return hdca


Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ def execute(
if input_value is None:
default_value = step.get_input_default_value(NO_REPLACEMENT)
if default_value is not NO_REPLACEMENT:
input_value = raw_to_galaxy(trans, default_value)
input_value = raw_to_galaxy(trans.app, trans.history, default_value)

step_outputs = dict(output=input_value)

Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/workflow/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

if TYPE_CHECKING:
from galaxy.model import (
HistoryItem,
Workflow,
WorkflowOutput,
WorkflowStep,
Expand Down Expand Up @@ -422,6 +423,7 @@ def replacement_for_input(self, trans, step: "WorkflowStep", input_dict: Dict[st
modules.NoReplacement,
model.DatasetCollectionInstance,
List[model.DatasetCollectionInstance],
"HistoryItem",
] = modules.NO_REPLACEMENT
prefixed_name = input_dict["name"]
multiple = input_dict["multiple"]
Expand All @@ -446,7 +448,7 @@ def replacement_for_input(self, trans, step: "WorkflowStep", input_dict: Dict[st
for step_input in step.inputs:
if step_input.name == prefixed_name and step_input.default_value_set:
if is_data:
replacement = raw_to_galaxy(trans, step_input.default_value)
replacement = raw_to_galaxy(trans.app, trans.history, step_input.default_value)
return replacement

def replacement_for_connection(self, connection: "WorkflowStepConnection", is_data: bool = True):
Expand Down Expand Up @@ -713,7 +715,7 @@ def subworkflow_progress(
)

def raw_to_galaxy(self, value: dict):
return raw_to_galaxy(self.module_injector.trans, value)
return raw_to_galaxy(self.module_injector.trans.app, self.module_injector.trans.history, value)

def _recover_mapping(self, step_invocation: WorkflowInvocationStep) -> None:
try:
Expand Down

0 comments on commit 1e95836

Please sign in to comment.