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
4 changes: 3 additions & 1 deletion sagemaker-core/src/sagemaker/core/workflow/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str]
"""

# FrameworkProcessor
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical bug in the diff: It appears the if source_dir: line was removed (shown as - if source_dir: in the diff), but the indented block below it still expects that conditional guard. This would cause the code under the old if source_dir: block to execute unconditionally, meaning when source_dir=None, the function would attempt urlparse(None) instead of falling through to the code-only path.

The fix should be:

dependencies = dependencies or []

if source_dir:
    source_dir_url = urlparse(source_dir)

Please verify the diff is correct — the if source_dir: line must be preserved. If this is a diff rendering issue, please confirm the actual file still contains the conditional.

if source_dir:
dependencies = dependencies or []


source_dir_url = urlparse(source_dir)
if source_dir_url.scheme == "" or source_dir_url.scheme == "file":
# Include code in the hash when possible
Expand Down
27 changes: 27 additions & 0 deletions sagemaker-core/tests/unit/workflow/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,33 @@ def test_get_processing_code_hash_s3_uri(self):

assert result is None

def test_get_processing_code_hash_with_none_dependencies(self):
"""Test get_processing_code_hash with None dependencies does not raise TypeError"""
with tempfile.TemporaryDirectory() as temp_dir:
code_file = Path(temp_dir, "script.py")
code_file.write_text("print('hello')")

result = get_processing_code_hash(
code=str(code_file), source_dir=temp_dir, dependencies=None
)

assert result is not None
assert len(result) == 64

def test_get_processing_code_hash_code_only_with_none_dependencies(self):
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This test uses tempfile.NamedTemporaryFile with manual os.unlink cleanup, while the test above uses tempfile.TemporaryDirectory which handles cleanup automatically. Consider using TemporaryDirectory here as well for consistency, or at minimum use a pytest.fixture / context manager pattern to ensure cleanup even if an assertion fails before finally. That said, the try/finally does handle it — this is a minor style suggestion.

"""Test get_processing_code_hash with code only and None dependencies"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
f.write("print('hello')")
temp_file = f.name

try:
result = get_processing_code_hash(code=temp_file, source_dir=None, dependencies=None)

assert result is not None
assert len(result) == 64
finally:
os.unlink(temp_file)

def test_get_processing_code_hash_with_dependencies(self):
"""Test get_processing_code_hash with dependencies"""
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down
Loading