Skip to content

Commit

Permalink
Fix bug in paired/unpaired.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jan 23, 2025
1 parent df0e99f commit 3716548
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
21 changes: 16 additions & 5 deletions lib/galaxy/model/dataset_collections/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def dataset_instances(self):
def elements(self):
raise NotImplementedError()

def to_adapter_model(self, adapting):
def to_adapter_model(self):
# json kwds to recover state from database after the job has been
# recorded
raise NotImplementedError()
Expand Down Expand Up @@ -110,12 +110,19 @@ def elements(self):
def adapting(self):
return self._dce

@property
def _adapting_src_dict(self):
return {
"src": "dce",
"id": self._dce.id,
}


class PromoteCollectionElementToCollectionAdapter(DCECollectionAdapter):
# allow a singleton list element to act as paired_or_unpaired collection

def to_adapter_model(self, adapting) -> AdaptedDataCollectionPromoteCollectionElementToCollectionRequestInternal:
adapting_model = DatasetCollectionElementReference.model_validate(adapting)
def to_adapter_model(self) -> AdaptedDataCollectionPromoteCollectionElementToCollectionRequestInternal:
adapting_model = DatasetCollectionElementReference.model_validate(self._adapting_src_dict)
return AdaptedDataCollectionPromoteCollectionElementToCollectionRequestInternal(
src="CollectionAdapter",
adapter_type="PromoteCollectionElementToCollection",
Expand All @@ -134,7 +141,11 @@ def __init__(self, hda: "HistoryDatasetAssociation", collection_type: str):
self._hda = hda
self._collection_type = collection_type

def to_adapter_model(self, adapting) -> AdaptedDataCollectionPromoteDatasetToCollectionRequestInternal:
def to_adapter_model(self) -> AdaptedDataCollectionPromoteDatasetToCollectionRequestInternal:
adapting = {
"src": "hda",
"id": self._hda.id,
}
adapting_model = DataRequestInternalHda.model_validate(adapting)
return AdaptedDataCollectionPromoteDatasetToCollectionRequestInternal(
src="CollectionAdapter",
Expand Down Expand Up @@ -186,7 +197,7 @@ def __init__(self, elements: List["TransientCollectionAdapterDatasetInstanceElem
self._collection_type = collection_type
self._elements = elements

def to_adapter_model(self, adapting) -> AdaptedDataCollectionPromoteDatasetsToCollectionRequestInternal:
def to_adapter_model(self) -> AdaptedDataCollectionPromoteDatasetsToCollectionRequestInternal:
element_models = []
for element in self._elements:
element_model = AdapterElementRequestInternal(
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tools/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def _record_inputs(self, trans, tool, job, incoming, inp_data, inp_dataset_colle
# of datasets -> collection adaption because it isn't clear where to track that
# (see elif isinstance(adapting, list) branch below).
adapting = adapter.adapting
adapter_model = cast(BaseModel, adapter.to_adapter_model(adapting))
adapter_model = cast(BaseModel, adapter.to_adapter_model())
if isinstance(adapting, model.DatasetCollectionElement):
job.add_input_dataset_collection_element(
name, adapting, adapter_json=adapter_model.model_dump()
Expand Down
10 changes: 1 addition & 9 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,13 +2875,7 @@ def history_item_to_json(value, app, use_security):
collection_adapter: Optional[CollectionAdapter] = None
if isinstance(value, CollectionAdapter):
collection_adapter = value
value = value.adapting
if isinstance(value, list):
# if we are not just adapting one thing... skip the rest of this
# and just serialize the stuff we know we want anyway. Perhaps all
# this should just be the only path through. The CollectionAdapter
# should know what to do with just use_security I think?
return collection_adapter.to_adapter_model(value).dict()
return collection_adapter.to_adapter_model().dict()
if isinstance(value, MutableMapping) and "src" in value and "id" in value:
return value
elif isinstance(value, DatasetCollectionElement):
Expand All @@ -2898,6 +2892,4 @@ def history_item_to_json(value, app, use_security):
if src is not None:
object_id = cached_id(value)
rval = {"id": app.security.encode_id(object_id) if use_security else object_id, "src": src}
if collection_adapter:
rval = collection_adapter.to_adapter_model(rval).dict()
return rval

0 comments on commit 3716548

Please sign in to comment.