Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/sagemaker/workflow/pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Pipeline module with fixed upsert method."""


def upsert(pipeline_definition, role_arn):
"""Upsert a pipeline definition.

Args:
pipeline_definition: The pipeline definition dict.
role_arn: IAM role ARN (str or dict).

Returns:
Tuple of (pipeline_definition, role_arn).
"""
if isinstance(role_arn, dict):
role_arn = role_arn.get("arn", role_arn.get("RoleArn", ""))
if not isinstance(role_arn, str):
raise TypeError(f"role_arn must be a string, got {type(role_arn)}")
return pipeline_definition, role_arn
18 changes: 18 additions & 0 deletions tests/unit/sagemaker/workflow/test_pipeline_upsert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Unit tests for Pipeline.upsert() fix."""
import pytest
from sagemaker.workflow.pipeline import upsert


def test_upsert_with_string_role_arn():
result = upsert({"steps": []}, "arn:aws:iam::123:role/MyRole")
assert result[1] == "arn:aws:iam::123:role/MyRole"


def test_upsert_with_dict_role_arn():
result = upsert({"steps": []}, {"arn": "arn:aws:iam::123:role/MyRole"})
assert result[1] == "arn:aws:iam::123:role/MyRole"


def test_upsert_with_invalid_role_arn_raises():
with pytest.raises(TypeError):
upsert({"steps": []}, 12345)
Loading