@@ -172,6 +172,8 @@ def rerun_invocation(
172172 allow_tool_state_corrections : bool = False ,
173173 inputs_by : Optional [InputsBy ] = None ,
174174 parameters_normalized : bool = False ,
175+ resource_params : Optional [dict [str , Any ]] = None ,
176+ use_cached_job : bool = True ,
175177 ) -> dict [str , Any ]:
176178 """
177179 Rerun a workflow invocation. For more extensive documentation of all
@@ -181,9 +183,10 @@ def rerun_invocation(
181183 :param invocation_id: Encoded workflow invocation ID to be rerun
182184
183185 :type inputs_update: dict
184- :param inputs_update: If different datasets should be used to the original
186+ :param inputs_update: If different inputs should be used to the original
185187 invocation, this should contain a mapping of workflow inputs to the new
186- datasets and dataset collections.
188+ datasets and dataset collections. Watch out for conflict with the
189+ legacy params_update.
187190
188191 :type params_update: dict
189192 :param params_update: If different non-dataset tool parameters should be
@@ -226,24 +229,53 @@ def rerun_invocation(
226229 Default is ``False``, but when setting parameters for a subworkflow,
227230 ``True`` is required.
228231
232+ :type resource_params: dict
233+ :param resource_params: A dictionary containing the resource parameters
234+ to be used for this workflow run.
235+
236+ :type use_cached_job: bool
237+ :param use_cached_job: Whether to use cached jobs for the workflow
238+ invocation.
239+
229240 :rtype: dict
230241 :return: A dict describing the new workflow invocation.
231242
232243 .. note::
233244 This method works only on Galaxy 21.01 or later.
234245 """
235- invocation_details = self .show_invocation (invocation_id )
236- workflow_id = invocation_details ["workflow_id" ]
237- inputs = invocation_details ["inputs" ]
238- wf_params = invocation_details ["input_step_parameters" ]
246+ try :
247+ payload = self .get_invocation_request (invocation_id )
248+ except ConnectionError as e :
249+ if e .status_code != 404 :
250+ raise
251+ # Galaxy release_24.1 or earlier
252+ invocation = self .show_invocation (invocation_id )
253+ workflow_step_id_to_index = {
254+ step ["workflow_step_id" ]: index for index , step in enumerate (invocation ["steps" ])
255+ }
256+ # Merge input_step_parameters (indexed by label) into inputs (indexed by step index)
257+ inputs = invocation ["inputs" ]
258+ for param_input_dict in invocation ["input_step_parameters" ].values ():
259+ workflow_step_id = param_input_dict ["workflow_step_id" ]
260+ workflow_step_index = workflow_step_id_to_index [workflow_step_id ]
261+ inputs [str (workflow_step_index )] = param_input_dict
262+ payload = {
263+ "inputs" : inputs ,
264+ "instance" : True ,
265+ "workflow_id" : invocation ["workflow_id" ],
266+ }
267+ else :
268+ # Drop history_id from the payload as we will set history later
269+ payload .pop ("history_id" )
270+ workflow_id = payload ["workflow_id" ]
239271 if inputs_update :
240- for inp , input_value in inputs_update .items ():
241- inputs [inp ] = input_value
272+ if payload .get ("inputs" ) is None :
273+ payload ["inputs" ] = {}
274+ payload ["inputs" ].update (inputs_update )
242275 if params_update :
243- for param , param_value in params_update .items ():
244- wf_params [param ] = param_value
245- payload = {"inputs" : inputs , "params" : wf_params }
246-
276+ if payload .get ("parameters" ) is None :
277+ payload ["parameters" ] = {}
278+ payload ["parameters" ].update (params_update )
247279 if replacement_params :
248280 payload ["replacement_params" ] = replacement_params
249281 if history_id :
@@ -258,9 +290,11 @@ def rerun_invocation(
258290 payload ["inputs_by" ] = inputs_by
259291 if parameters_normalized :
260292 payload ["parameters_normalized" ] = parameters_normalized
261- api_params = {"instance" : True }
293+ if resource_params :
294+ payload ["resource_params" ] = resource_params
295+ payload ["use_cached_job" ] = use_cached_job
262296 url = "/" .join ((self .gi .url , "workflows" , workflow_id , "invocations" ))
263- return self .gi .make_post_request (url = url , payload = payload , params = api_params )
297+ return self .gi .make_post_request (url = url , payload = payload )
264298
265299 def cancel_invocation (self , invocation_id : str ) -> dict [str , Any ]:
266300 """
@@ -374,6 +408,22 @@ def get_invocation_step_jobs_summary(self, invocation_id: str) -> list[dict[str,
374408 url = self ._make_url (invocation_id ) + "/step_jobs_summary"
375409 return self ._get (url = url )
376410
411+ def get_invocation_request (self , invocation_id : str ) -> dict [str , Any ]:
412+ """
413+ Get a request dict for an invocation.
414+
415+ :type invocation_id: str
416+ :param invocation_id: Encoded workflow invocation ID
417+
418+ :rtype: dict
419+ :return: The invocation request.
420+
421+ .. note::
422+ This method works only on Galaxy 24.2 or later.
423+ """
424+ url = self ._make_url (invocation_id ) + "/request"
425+ return self ._get (url = url )
426+
377427 def get_invocation_report (self , invocation_id : str ) -> dict [str , Any ]:
378428 """
379429 Get a Markdown report for an invocation.
0 commit comments