Skip to content

Commit 2c02204

Browse files
fix: merge tags instead of delete
1 parent 1c7f167 commit 2c02204

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/sagemaker/workflow/pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ def upsert(
187187
ResourceArn=response["PipelineArn"]
188188
)["Tags"]
189189

190-
tag_keys = [tag["Key"] for tag in old_tags]
190+
tag_keys = [tag["Key"] for tag in tags]
191+
for old_tag in old_tags:
192+
if old_tag["Key"] not in tag_keys:
193+
tags.append(old_tag)
191194

192-
self.sagemaker_session.sagemaker_client.delete_tags(
193-
ResourceArn=response["PipelineArn"], TagKeys=tag_keys
194-
)
195195
self.sagemaker_session.sagemaker_client.add_tags(
196196
ResourceArn=response["PipelineArn"], Tags=tags
197197
)

tests/integ/test_workflow.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,28 +459,32 @@ def test_one_step_sklearn_processing_pipeline(
459459
# under a potentially different role, often requiring access to S3 and other
460460
# artifacts not required to during creation of the jobs in the pipeline steps.
461461
response = pipeline.create(
462-
role, tags=[{"Key": "foo", "Value": "abc"}, {"Key": "bar", "Value": "xyz"}]
462+
role, tags=[{"Key": "foo", "Value": "123"}, {"Key": "bar", "Value": "456"}]
463463
)
464464
create_arn = response["PipelineArn"]
465465
assert re.match(
466466
fr"arn:aws:sagemaker:{region_name}:\d{{12}}:pipeline/{pipeline_name}",
467467
create_arn,
468468
)
469469
original_tags = sagemaker_session.sagemaker_client.list_tags(ResourceArn=create_arn)
470-
for tag in [{"Key": "foo", "Value": "abc"}, {"Key": "bar", "Value": "xyz"}]:
470+
for tag in [{"Key": "foo", "Value": "123"}, {"Key": "bar", "Value": "456"}]:
471471
assert tag in original_tags["Tags"]
472472

473473
pipeline.parameters = [ParameterInteger(name="InstanceCount", default_value=1)]
474474
response = pipeline.upsert(
475-
role, tags=[{"Key": "abc", "Value": "foo"}, {"Key": "xyz", "Value": "bar"}]
475+
role, tags=[{"Key": "foo", "Value": "abc"}, {"Key": "baz", "Value": "789"}]
476476
)
477477
update_arn = response["PipelineArn"]
478478
assert re.match(
479479
fr"arn:aws:sagemaker:{region_name}:\d{{12}}:pipeline/{pipeline_name}",
480480
update_arn,
481481
)
482482
updated_tags = sagemaker_session.sagemaker_client.list_tags(ResourceArn=create_arn)
483-
for tag in [{"Key": "abc", "Value": "foo"}, {"Key": "xyz", "Value": "bar"}]:
483+
for tag in [
484+
{"Key": "foo", "Value": "abc"},
485+
{"Key": "bar", "Value": "456"},
486+
{"Key": "baz", "Value": "789"},
487+
]:
484488
assert tag in updated_tags["Tags"]
485489

486490
execution = pipeline.start(parameters={})

tests/unit/sagemaker/workflow/test_pipeline.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def test_pipeline_upsert(sagemaker_session_mock, role_arn):
105105
{"PipelineArn": "mock_pipeline_arn"},
106106
[{"Key": "dummy", "Value": "dummy_tag"}],
107107
{},
108-
{},
109108
]
110109

111110
pipeline = Pipeline(
@@ -129,9 +128,8 @@ def test_pipeline_upsert(sagemaker_session_mock, role_arn):
129128
assert sagemaker_session_mock.sagemaker_client.list_tags.called_with(
130129
ResourceArn="mock_pipeline_arn"
131130
)
132-
assert sagemaker_session_mock.sagemaker_client.delete_tags(
133-
ResourceArn="mock_pipeline_arn", TagKeys=["dummy"]
134-
)
131+
132+
tags.append({"Key": "dummy", "Value": "dummy_tag"})
135133
assert sagemaker_session_mock.sagemaker_client.add_tags.called_with(
136134
ResourceArn="mock_pipeline_arn", Tags=tags
137135
)

0 commit comments

Comments
 (0)