Skip to content

Commit b1d588c

Browse files
committed
feature: allow opt out from referencing latest execution in the selec… (aws#1004)
1 parent 75e1d08 commit b1d588c

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/sagemaker/workflow/pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ def start(
344344
A `_PipelineExecution` instance, if successful.
345345
"""
346346
if selective_execution_config is not None:
347-
if selective_execution_config.source_pipeline_execution_arn is None:
347+
if (
348+
selective_execution_config.source_pipeline_execution_arn is None
349+
and selective_execution_config.reference_latest_execution
350+
):
348351
selective_execution_config.source_pipeline_execution_arn = (
349352
self._get_latest_execution_arn()
350353
)

src/sagemaker/workflow/selective_execution_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ class SelectiveExecutionConfig:
2222
another SageMaker pipeline run.
2323
"""
2424

25-
def __init__(self, selected_steps: List[str], source_pipeline_execution_arn: str = None):
25+
def __init__(
26+
self,
27+
selected_steps: List[str],
28+
source_pipeline_execution_arn: str = None,
29+
reference_latest_execution: bool = True,
30+
):
2631
"""Create a `SelectiveExecutionConfig`.
2732
2833
Args:
@@ -32,9 +37,12 @@ def __init__(self, selected_steps: List[str], source_pipeline_execution_arn: str
3237
`Succeeded`.
3338
selected_steps (List[str]): A list of pipeline steps to run. All step(s) in all
3439
path(s) between two selected steps should be included.
40+
reference_latest_execution (bool): Whether to reference the latest execution if
41+
source_pipeline_execution_arn is not provided.
3542
"""
3643
self.source_pipeline_execution_arn = source_pipeline_execution_arn
3744
self.selected_steps = selected_steps
45+
self.reference_latest_execution = reference_latest_execution
3846

3947
def _build_selected_steps_from_list(self) -> RequestType:
4048
"""Get the request structure for the list of selected steps."""

tests/unit/sagemaker/workflow/test_pipeline.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ def test_pipeline_start_selective_execution(sagemaker_session_mock):
492492
"SourcePipelineExecutionArn": "foo-arn",
493493
},
494494
)
495+
sagemaker_session_mock.reset_mock()
495496

496497
# Case 2: Start selective execution without SourcePipelineExecutionArn
498+
# References latest execution by default.
497499
sagemaker_session_mock.sagemaker_client.list_pipeline_executions.return_value = {
498500
"PipelineExecutionSummaries": [
499501
{
@@ -523,6 +525,27 @@ def test_pipeline_start_selective_execution(sagemaker_session_mock):
523525
"SourcePipelineExecutionArn": "my:latest:execution:arn",
524526
},
525527
)
528+
sagemaker_session_mock.reset_mock()
529+
530+
# Case 3: Start selective execution without SourcePipelineExecutionArn
531+
# Opts not to reference latest execution.
532+
selective_execution_config = SelectiveExecutionConfig(
533+
selected_steps=["step-1", "step-2", "step-3"],
534+
reference_latest_execution=False,
535+
)
536+
pipeline.start(selective_execution_config=selective_execution_config)
537+
sagemaker_session_mock.sagemaker_client.list_pipeline_executions.assert_not_called()
538+
sagemaker_session_mock.sagemaker_client.start_pipeline_execution.assert_called_with(
539+
PipelineName="MyPipeline",
540+
SelectiveExecutionConfig={
541+
"SelectedSteps": [
542+
{"StepName": "step-1"},
543+
{"StepName": "step-2"},
544+
{"StepName": "step-3"},
545+
],
546+
},
547+
)
548+
sagemaker_session_mock.reset_mock()
526549

527550

528551
def test_pipeline_basic():

0 commit comments

Comments
 (0)