@@ -8779,19 +8779,18 @@ def create_run_step(self, step_run: StepRunRequest) -> StepRunResponse:
87798779 session .commit ()
87808780 session .refresh (step_schema )
87818781
8782- # Save parent step IDs into the database.
8783- for parent_step_id in step_run .parent_step_ids :
8784- self ._set_run_step_parent_step (
8785- child_step_run = step_schema ,
8786- parent_id = parent_step_id ,
8787- session = session ,
8788- )
8789-
87908782 session .commit ()
87918783 session .refresh (step_schema )
87928784
87938785 step_model = step_schema .to_model (include_metadata = True )
87948786
8787+ for upstream_step in step_model .spec .upstream_steps :
8788+ self ._set_run_step_parent_step (
8789+ child_step_run = step_schema ,
8790+ parent_step_name = upstream_step ,
8791+ session = session ,
8792+ )
8793+
87958794 # Save input artifact IDs into the database.
87968795 for input_name , artifact_version_ids in step_run .inputs .items ():
87978796 for artifact_version_id in artifact_version_ids :
@@ -9047,22 +9046,33 @@ def _get_step_run_input_type_from_config(
90479046 return StepRunInputArtifactType .MANUAL
90489047
90499048 def _set_run_step_parent_step (
9050- self , child_step_run : StepRunSchema , parent_id : UUID , session : Session
9049+ self ,
9050+ child_step_run : StepRunSchema ,
9051+ parent_step_name : str ,
9052+ session : Session ,
90519053 ) -> None :
90529054 """Sets the parent step run for a step run.
90539055
90549056 Args:
90559057 child_step_run: The child step run to set the parent for.
9056- parent_id : The ID of the parent step run to set a child for.
9058+ parent_step_name : The name of the parent step run to set a child for.
90579059 session: The database session to use.
9060+
9061+ Raises:
9062+ RuntimeError: If the parent step run is not found.
90589063 """
9059- parent_step_run = self ._get_reference_schema_by_id (
9060- resource = child_step_run ,
9061- reference_schema = StepRunSchema ,
9062- reference_id = parent_id ,
9063- session = session ,
9064- reference_type = "parent step" ,
9065- )
9064+ parent_step_run = session .exec (
9065+ select (StepRunSchema )
9066+ .where (StepRunSchema .name == parent_step_name )
9067+ .where (
9068+ StepRunSchema .pipeline_run_id == child_step_run .pipeline_run_id
9069+ )
9070+ ).first ()
9071+ if parent_step_run is None :
9072+ raise RuntimeError (
9073+ f"Parent step run `{ parent_step_name } ` not found for step run "
9074+ f"`{ child_step_run .name } `."
9075+ )
90669076
90679077 # Check if the parent step is already set.
90689078 assignment = session .exec (
0 commit comments