diff --git a/lib/galaxy/tool_util/client/staging.py b/lib/galaxy/tool_util/client/staging.py index dd3bad54d966..c4f6558dee2a 100644 --- a/lib/galaxy/tool_util/client/staging.py +++ b/lib/galaxy/tool_util/client/staging.py @@ -59,18 +59,16 @@ def _post(self, api_path: str, payload: Dict[str, Any]) -> Dict[str, Any]: def _attach_file(self, path: str) -> BinaryIO: return open(path, "rb") - def _tools_post(self, payload: Dict[str, Any]) -> Dict[str, Any]: + def _job_details_from_tool_response(self, tool_response: Dict[str, Any]) -> List[Dict[str, Any]]: + return [self._handle_job(job) for job in tool_response.get("jobs", [])] + + def _tools_post(self, payload: Dict[str, Any]) -> List[Dict[str, Any]]: tool_response = self._post("tools", payload) - for job in tool_response.get("jobs", []): - self._handle_job(job) - return tool_response + return self._job_details_from_tool_response(tool_response) def _fetch_post(self, payload: Dict[str, Any]) -> List[Dict[str, Any]]: tool_response = self._post("tools/fetch", payload) - job_details = [] - for job in tool_response.get("jobs", []): - job_details.append(self._handle_job(job)) - return job_details + return self._job_details_from_tool_response(tool_response) @abc.abstractmethod def _handle_job(self, job_response: Dict[str, Any]) -> Dict[str, Any]: @@ -206,12 +204,12 @@ def _attach_file(upload_payload: Dict[str, Any], uri: str, index: int = 0) -> No _attach_file(upload_payload, composite_data, index=i) self._log(f"upload_payload is {upload_payload}") - return self._tools_post(upload_payload) + return self._tools_post(upload_payload)[0] elif isinstance(upload_target, FileLiteralTarget): # For file literals - take them as is - never convert line endings. payload = _upload_payload(history_id, file_type="auto", auto_decompress=False, to_posix_lines=False) payload["inputs"]["files_0|url_paste"] = upload_target.contents - return self._tools_post(payload) + return self._tools_post(payload)[0] elif isinstance(upload_target, DirectoryUploadTarget): tar_path = upload_target.tar_path @@ -221,20 +219,21 @@ def _attach_file(upload_payload: Dict[str, Any], uri: str, index: int = 0) -> No ) upload_payload["inputs"]["files_0|auto_decompress"] = False _attach_file(upload_payload, tar_path) - tar_upload_response = self._tools_post(upload_payload) + tar_upload_first_job_details = self._tools_post(upload_payload)[0] + tar_upload_first_dataset_id = next(iter(tar_upload_first_job_details["outputs"].values()))["id"] convert_payload = dict( tool_id="CONVERTER_tar_to_directory", - tool_inputs={"input1": {"src": "hda", "id": tar_upload_response["outputs"][0]["id"]}}, + tool_inputs={"input1": {"src": "hda", "id": tar_upload_first_dataset_id}}, history_id=history_id, ) - convert_response = self._tools_post(convert_payload) + convert_response = self._tools_post(convert_payload)[0] assert "outputs" in convert_response, convert_response return convert_response elif isinstance(upload_target, ObjectUploadTarget): content = json.dumps(upload_target.object) payload = _upload_payload(history_id, file_type="expression.json") payload["files_0|url_paste"] = content - return self._tools_post(payload) + return self._tools_post(payload)[0] else: raise ValueError(f"Unsupported type for upload_target: {type(upload_target)}")