Skip to content

Commit b6a40b0

Browse files
authored
Merge pull request #20694 from arash77/fix_encoded_id_datasets_on_release_25.0
[25.0] Fix dataset serializers and response models
2 parents 48a3dd6 + ce52a72 commit b6a40b0

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

client/src/api/schema/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11284,6 +11284,11 @@ export interface components {
1128411284
copied_from_history_dataset_association_id?: string | null;
1128511285
/** Copied From Ldda Id */
1128611286
copied_from_ldda_id?: string | null;
11287+
/**
11288+
* Copied From Library Dataset Dataset Association Id
11289+
* @description ID of LDDA this HDA was copied from.
11290+
*/
11291+
copied_from_library_dataset_dataset_association_id?: string | null;
1128711292
/**
1128811293
* Create Time
1128911294
* @description The time and date this item was created.
@@ -11533,6 +11538,11 @@ export interface components {
1153311538
copied_from_history_dataset_association_id?: string | null;
1153411539
/** Copied From Ldda Id */
1153511540
copied_from_ldda_id?: string | null;
11541+
/**
11542+
* Copied From Library Dataset Dataset Association Id
11543+
* @description ID of LDDA this HDA was copied from.
11544+
*/
11545+
copied_from_library_dataset_dataset_association_id?: string | null;
1153611546
/**
1153711547
* Create Time
1153811548
* @description The time and date this item was created.

lib/galaxy/managers/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def add_serializers(self):
652652
"file_size": lambda item, key, **context: self.serializers["size"](item, key, **context),
653653
"nice_size": lambda item, key, **context: item.get_size(nice_size=True, calculate_size=False),
654654
# common to lddas and hdas - from mapping.py
655-
"copied_from_history_dataset_association_id": lambda item, key, **context: item.id,
655+
"copied_from_history_dataset_association_id": self.serialize_id,
656656
"copied_from_library_dataset_dataset_association_id": self.serialize_id,
657657
"info": lambda item, key, **context: item.info.strip() if isinstance(item.info, str) else item.info,
658658
"blurb": lambda item, key, **context: item.blurb,

lib/galaxy/managers/hdas.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,6 @@ def __init__(self, app: StructuredApp):
576576
["accessible", "id", "name", "history_id", "hid", "history_content_type", "state", "deleted", "visible"],
577577
)
578578

579-
def serialize_copied_from_ldda_id(self, item, key, **context):
580-
"""
581-
Serialize an id attribute of `item`.
582-
"""
583-
if item.copied_from_library_dataset_dataset_association is not None:
584-
return self.app.security.encode_id(item.copied_from_library_dataset_dataset_association.id)
585-
return None
586-
587579
def add_serializers(self):
588580
super().add_serializers()
589581
taggable.TaggableSerializerMixin.add_serializers(self)
@@ -595,7 +587,9 @@ def add_serializers(self):
595587
"history_content_type": lambda item, key, **context: "dataset",
596588
"hda_ldda": lambda item, key, **context: "hda",
597589
"type_id": self.serialize_type_id,
598-
"copied_from_ldda_id": self.serialize_copied_from_ldda_id,
590+
"copied_from_ldda_id": lambda item, key, **context: self.serialize_id(
591+
item, "copied_from_library_dataset_dataset_association_id", **context
592+
),
599593
"history_id": self.serialize_id,
600594
# remapped
601595
"misc_info": self._remap_from("info"),

lib/galaxy/schema/schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ class HDADetailed(HDASummary, WithModelClass):
942942
copied_from_history_dataset_association_id: Annotated[
943943
Optional[EncodedDatabaseIdField], Field(None, description="ID of HDA this HDA was copied from.")
944944
]
945+
copied_from_library_dataset_dataset_association_id: Annotated[
946+
Optional[EncodedDatabaseIdField], Field(None, description="ID of LDDA this HDA was copied from.")
947+
]
945948

946949

947950
class HDAExtended(HDADetailed):

lib/galaxy_test/api/test_datasets.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,33 @@ def test_download_non_english_characters(self, history_id):
920920
response = self._get(f"histories/{history_id}/contents/{hda['id']}/display?to_ext=json")
921921
self._assert_status_code_is(response, 200)
922922
assert quote(name, safe="") in response.headers["Content-Disposition"]
923+
924+
def test_copy_dataset_from_history_with_copied_from_fields(self, history_id):
925+
original_hda = self.dataset_populator.new_dataset(history_id, content="original data", wait=True)
926+
self._assert_copied_from_fields(history_id, original_hda["id"], None, None, None)
927+
928+
copy_payload = {"content": original_hda["id"], "source": "hda", "type": "dataset"}
929+
copied_hda_id = self._post(f"histories/{history_id}/contents", data=copy_payload, json=True).json()["id"]
930+
self._assert_copied_from_fields(history_id, copied_hda_id, original_hda["id"], None, None)
931+
932+
@requires_new_library
933+
def test_copy_dataset_from_library_with_copied_from_fields(self, history_id):
934+
library_dataset = self.library_populator.new_library_dataset("test_library_dataset")
935+
copy_payload = {"content": library_dataset["id"], "source": "library", "type": "dataset"}
936+
copied_hda_id = self._post(f"histories/{history_id}/contents", data=copy_payload, json=True).json()["id"]
937+
self._assert_copied_from_fields(
938+
history_id, copied_hda_id, None, library_dataset["ldda_id"], library_dataset["ldda_id"]
939+
)
940+
941+
def _assert_copied_from_fields(
942+
self, history_id, hda_id, expected_history_id, expected_ldda_id, expected_library_id
943+
):
944+
keys = "copied_from_history_dataset_association_id,copied_from_ldda_id,copied_from_library_dataset_dataset_association_id"
945+
for url in [
946+
f"datasets/{hda_id}?keys={keys}",
947+
f"histories/{history_id}/contents/datasets/{hda_id}?keys={keys}",
948+
]:
949+
data = self._get(url).json()
950+
assert data["copied_from_history_dataset_association_id"] == expected_history_id
951+
assert data["copied_from_ldda_id"] == expected_ldda_id
952+
assert data["copied_from_library_dataset_dataset_association_id"] == expected_library_id

test/unit/app/managers/test_HDAManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_serializers(self):
412412
assert isinstance(serialized["file_size"], int)
413413
assert isinstance(serialized["nice_size"], str)
414414
# TODO: these should be tested w/copy
415-
assert isinstance(serialized["copied_from_history_dataset_association_id"], int)
415+
self.assertNullableEncodedId(serialized["copied_from_history_dataset_association_id"])
416416
self.assertNullableEncodedId(serialized["copied_from_library_dataset_dataset_association_id"])
417417
self.assertNullableBasestring(serialized["info"])
418418
self.assertNullableBasestring(serialized["blurb"])

0 commit comments

Comments
 (0)