Skip to content

Commit 9e8230c

Browse files
nmadanNamrata Madan
andauthored
fix: adjacent slash in s3 key (#3427)
Co-authored-by: Namrata Madan <[email protected]>
1 parent 5adc2d3 commit 9e8230c

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/sagemaker/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ def _upload_code(self, key_prefix: str, repack: bool = False) -> None:
569569
)
570570
return
571571
self.sagemaker_session.context.need_runtime_repack.add(id(self))
572-
self.sagemaker_session.context.runtime_repack_output_prefix = "s3://{}/{}".format(
573-
bucket, key_prefix
572+
self.sagemaker_session.context.runtime_repack_output_prefix = s3.s3_path_join(
573+
"s3://", bucket, key_prefix
574574
)
575575
# Add the uploaded_code and repacked_model_data to update the container env
576576
self.repacked_model_data = self.model_data

src/sagemaker/tensorflow/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ def prepare_container_def(
396396
# model is not yet there, defer repacking to later during pipeline execution
397397
if isinstance(self.sagemaker_session, PipelineSession):
398398
self.sagemaker_session.context.need_runtime_repack.add(id(self))
399-
self.sagemaker_session.context.runtime_repack_output_prefix = "s3://{}/{}".format(
400-
bucket, key_prefix
399+
self.sagemaker_session.context.runtime_repack_output_prefix = s3.s3_path_join(
400+
"s3://", bucket, key_prefix
401401
)
402402
else:
403403
logging.warning(

tests/unit/sagemaker/workflow/test_model_step.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
_TENSORFLOW_PATH = os.path.join(DATA_DIR, "tfs/tfs-test-entrypoint-and-dependencies")
7171
_REPACK_OUTPUT_KEY_PREFIX = "code-output"
7272
_MODEL_CODE_LOCATION = f"s3://{_BUCKET}/{_REPACK_OUTPUT_KEY_PREFIX}"
73+
_MODEL_CODE_LOCATION_TRAILING_SLASH = _MODEL_CODE_LOCATION + "/"
7374

7475

7576
@pytest.fixture
@@ -701,7 +702,7 @@ def test_conditional_model_create_and_regis(
701702
entry_point=f"{DATA_DIR}/{_SCRIPT_NAME}",
702703
role=_ROLE,
703704
enable_network_isolation=True,
704-
code_location=_MODEL_CODE_LOCATION,
705+
code_location=_MODEL_CODE_LOCATION_TRAILING_SLASH,
705706
),
706707
2,
707708
),
@@ -725,7 +726,7 @@ def test_conditional_model_create_and_regis(
725726
entry_point=f"{DATA_DIR}/{_SCRIPT_NAME}",
726727
role=_ROLE,
727728
framework_version="1.5.0",
728-
code_location=_MODEL_CODE_LOCATION,
729+
code_location=_MODEL_CODE_LOCATION_TRAILING_SLASH,
729730
),
730731
2,
731732
),
@@ -757,7 +758,7 @@ def test_conditional_model_create_and_regis(
757758
image_uri=_IMAGE_URI,
758759
entry_point=f"{DATA_DIR}/{_SCRIPT_NAME}",
759760
role=_ROLE,
760-
code_location=_MODEL_CODE_LOCATION,
761+
code_location=_MODEL_CODE_LOCATION_TRAILING_SLASH,
761762
),
762763
2,
763764
),
@@ -780,7 +781,9 @@ def assert_test_result(steps: list):
780781
assert len(steps) == expected_step_num
781782
if expected_step_num == 2:
782783
assert steps[0]["Type"] == "Training"
783-
if model.key_prefix == _REPACK_OUTPUT_KEY_PREFIX:
784+
if model.key_prefix is not None and model.key_prefix.startswith(
785+
_REPACK_OUTPUT_KEY_PREFIX
786+
):
784787
assert steps[0]["Arguments"]["OutputDataConfig"]["S3OutputPath"] == (
785788
f"{_MODEL_CODE_LOCATION}/{model.name}"
786789
)

0 commit comments

Comments
 (0)