From 182c7d3648d6ff0baa55dfee7ffaa5ea87aa114a Mon Sep 17 00:00:00 2001 From: aviruthen <91846056+aviruthen@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:55:52 -0400 Subject: [PATCH] fix: Pipeline upsert TypeError (full e2e test 1773867349) (#88888) --- src/sagemaker/workflow/pipeline.py | 18 ++++++++++++++++++ .../sagemaker/workflow/test_pipeline_upsert.py | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/sagemaker/workflow/pipeline.py create mode 100644 tests/unit/sagemaker/workflow/test_pipeline_upsert.py diff --git a/src/sagemaker/workflow/pipeline.py b/src/sagemaker/workflow/pipeline.py new file mode 100644 index 0000000000..00939a7242 --- /dev/null +++ b/src/sagemaker/workflow/pipeline.py @@ -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 diff --git a/tests/unit/sagemaker/workflow/test_pipeline_upsert.py b/tests/unit/sagemaker/workflow/test_pipeline_upsert.py new file mode 100644 index 0000000000..85c53ff974 --- /dev/null +++ b/tests/unit/sagemaker/workflow/test_pipeline_upsert.py @@ -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)