Skip to content

Commit c172675

Browse files
svia3svia3
authored andcommitted
fix: add warning message for job-prefixed pipeline steps when no job name is provided (aws#4371)
Co-authored-by: svia3 <[email protected]>
1 parent 0d4bae9 commit c172675

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/sagemaker/workflow/utilities.py

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
"if desired."
4242
)
4343

44+
JOB_KEY_NONE_WARN_MSG_TEMPLATE = (
45+
"Invalid input: use_custom_job_prefix flag is set but the name field [{}] has not been "
46+
"specified. Please refer to the AWS Docs to identify which field should be set to enable the "
47+
"custom-prefixing feature for jobs created via a pipeline execution. "
48+
"https://docs.aws.amazon.com/sagemaker/latest/dg/"
49+
"build-and-manage-access.html#build-and-manage-step-permissions-prefix"
50+
)
51+
4452
if TYPE_CHECKING:
4553
from sagemaker.workflow.step_collections import StepCollection
4654

@@ -458,6 +466,8 @@ def trim_request_dict(request_dict, job_key, config):
458466
request_dict.pop(job_key, None) # safely return null in case of KeyError
459467
else:
460468
if job_key in request_dict:
469+
if request_dict[job_key] is None or len(request_dict[job_key]) == 0:
470+
raise ValueError(JOB_KEY_NONE_WARN_MSG_TEMPLATE.format(job_key))
461471
request_dict[job_key] = base_from_name(request_dict[job_key]) # trim timestamp
462472

463473
return request_dict

tests/unit/sagemaker/workflow/test_model_step.py

+28
Original file line numberDiff line numberDiff line change
@@ -1328,3 +1328,31 @@ def _validate_repack_job_non_configurable_args(
13281328
assert model_archive.expr == expected_model_archive
13291329
else:
13301330
assert model_archive == expected_model_archive
1331+
1332+
1333+
def test_create_model_step_using_custom_model_name_set_to_none(pipeline_session):
1334+
# Name of the model not specified, will resolve to None.
1335+
model = Model(
1336+
image_uri="my-image",
1337+
sagemaker_session=pipeline_session,
1338+
model_data="s3://",
1339+
role=ROLE,
1340+
)
1341+
step_create_model = ModelStep(name="MyModelStep", step_args=model.create())
1342+
1343+
# 1. Toggle on custom-prefixing model name set to None.
1344+
config = PipelineDefinitionConfig(use_custom_job_prefix=True)
1345+
1346+
with pytest.raises(ValueError) as error:
1347+
pipeline = Pipeline(
1348+
name="MyPipeline",
1349+
steps=[step_create_model],
1350+
sagemaker_session=pipeline_session,
1351+
pipeline_definition_config=config,
1352+
)
1353+
pipeline.definition()
1354+
1355+
assert (
1356+
"Invalid input: use_custom_job_prefix flag is set but the name field "
1357+
"[ModelName] has not been specified." in str(error.value)
1358+
)

0 commit comments

Comments
 (0)