diff --git a/lib/galaxy/webapps/galaxy/services/history_contents.py b/lib/galaxy/webapps/galaxy/services/history_contents.py index b3b7c4ad7bf..fa528db14c8 100644 --- a/lib/galaxy/webapps/galaxy/services/history_contents.py +++ b/lib/galaxy/webapps/galaxy/services/history_contents.py @@ -971,6 +971,7 @@ class HistoriesContentsService(ServiceBase): f"Invalid filter found. When requesting stats, please avoid filtering by {non_orm_filter_keys}" ) + serialization_params = self._handle_extra_serialization_for_media_type(serialization_params, accept) filter_query_params.order = filter_query_params.order or "hid-asc" order_by = self.build_order_by(self.history_contents_manager, filter_query_params.order) contents = self.history_contents_manager.contents( @@ -999,6 +1000,18 @@ class HistoriesContentsService(ServiceBase): return HistoryContentsWithStatsResult.construct(contents=items, stats=stats) return HistoryContentsResult.construct(__root__=items) + def _handle_extra_serialization_for_media_type( + self, + serialization_params: SerializationParams, + request_media_type: str, + ) -> SerializationParams: + """According to the requested media type the response may include extra information.""" + if request_media_type == HistoryContentsWithStatsResult.__accept_type__: + if not serialization_params.keys: + serialization_params.keys = [] + serialization_params.keys.append("elements_datatypes") + return serialization_params + def _serialize_legacy_content_item( self, trans, diff --git a/lib/galaxy_test/api/test_history_contents.py b/lib/galaxy_test/api/test_history_contents.py index 511aa61acfa..848b046a061 100644 --- a/lib/galaxy_test/api/test_history_contents.py +++ b/lib/galaxy_test/api/test_history_contents.py @@ -1138,6 +1138,20 @@ class HistoryContentsApiBulkOperationTestCase(ApiTestCase): ) self._assert_status_code_is(response, 400) + def test_index_with_stats_has_extra_serialization(self): + expected_extra_keys_in_collections = ["elements_datatypes"] + with self.dataset_populator.test_history() as history_id: + self._create_collection_in_history(history_id) + response = self._get_contents_with_stats( + history_id, + search_query="&q=history_content_type-eq&qv=dataset_collection", + ) + self._assert_status_code_is(response, 200) + contents_with_stats = response.json() + assert contents_with_stats["contents"] + collection = contents_with_stats["contents"][0] + self._assert_has_keys(collection, *expected_extra_keys_in_collections) + def _get_contents_with_stats(self, history_id: str, search_query: str = ""): headers = {"accept": "application/vnd.galaxy.history.contents.stats+json"} search_response = self._get(f"histories/{history_id}/contents?v=dev{search_query}", headers=headers)