@@ -445,6 +445,7 @@ def by_tool_input(
445445 param : ToolStateJobInstancePopulatedT ,
446446 param_dump : ToolStateDumpedToJsonInternalT ,
447447 job_state : Optional [JobStatesT ] = (Job .states .OK ,),
448+ history_id : Union [int , None ] = None ,
448449 require_name_match : bool = True ,
449450 ):
450451 """Search for jobs producing same results using the 'inputs' part of a tool POST."""
@@ -489,6 +490,7 @@ def populate_input_data_input_id(path, key, value):
489490 job_state = job_state ,
490491 param_dump = param_dump ,
491492 wildcard_param_dump = wildcard_param_dump ,
493+ history_id = history_id ,
492494 require_name_match = require_name_match ,
493495 )
494496
@@ -501,6 +503,7 @@ def __search(
501503 job_state : Optional [JobStatesT ],
502504 param_dump : ToolStateDumpedToJsonInternalT ,
503505 wildcard_param_dump = None ,
506+ history_id : Union [int , None ] = None ,
504507 require_name_match : bool = True ,
505508 ):
506509 search_timer = ExecutionTimer ()
@@ -566,7 +569,7 @@ def replace_dataset_ids(path, key, value):
566569 return None
567570
568571 stmt = stmt .where (* data_conditions ).group_by (model .Job .id , * used_ids )
569- stmt = self ._filter_jobs (stmt , tool_id , user .id , tool_version , job_state , wildcard_param_dump )
572+ stmt = self ._filter_jobs (stmt , tool_id , user .id , tool_version , job_state , wildcard_param_dump , history_id )
570573 stmt = self ._exclude_jobs_with_deleted_outputs (stmt )
571574
572575 for job in self .sa_session .execute (stmt ):
@@ -634,8 +637,15 @@ def replace_dataset_ids(path, key, value):
634637 return None
635638
636639 def _filter_jobs (
637- self , stmt , tool_id : str , user_id : int , tool_version : Optional [str ], job_state , wildcard_param_dump
638- ):
640+ self ,
641+ stmt : "Select[tuple[int]]" ,
642+ tool_id : str ,
643+ user_id : int ,
644+ tool_version : Optional [str ],
645+ job_state : Union [JobStatesT , None ],
646+ wildcard_param_dump ,
647+ history_id : Union [int , None ],
648+ ) -> "Select[tuple[int]]" :
639649 """Build subquery that selects a job with correct job parameters."""
640650 job_ids_materialized_cte = stmt .cte ("job_ids_cte" )
641651 outer_select_columns = [job_ids_materialized_cte .c [col .name ] for col in stmt .selected_columns ]
@@ -657,6 +667,9 @@ def _filter_jobs(
657667 if tool_version :
658668 stmt = stmt .where (Job .tool_version == str (tool_version ))
659669
670+ if history_id is not None :
671+ stmt = stmt .where (Job .history_id == history_id )
672+
660673 if job_state is None :
661674 job_states : set [str ] = {
662675 Job .states .NEW ,
0 commit comments