Skip to content

Commit 60bfc4b

Browse files
committed
fix: Pipeline TypeError: can only concatenate list (not "NoneType") to list Using Sou (aws#5518)
1 parent 6a1ba54 commit 60bfc4b

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

sagemaker-core/src/sagemaker/core/workflow/utilities.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def get_processing_dependencies(dependency_args: List[List[str]]) -> List[str]:
197197

198198

199199
def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str]) -> str:
200+
# Defensively handle None dependencies to prevent TypeError on list concatenation
201+
dependencies = dependencies or []
200202
"""Get the hash of a processing step's code artifact(s).
201203
202204
Args:

sagemaker-core/tests/unit/workflow/test_utilities.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,35 @@ def test_get_processing_code_hash_s3_uri(self):
250250
assert result is None
251251

252252
def test_get_processing_code_hash_with_dependencies(self):
253+
254+
def test_get_processing_code_hash_with_none_dependencies(self):
255+
"""Test get_processing_code_hash with None dependencies does not raise TypeError"""
256+
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
257+
f.write("print('hello')")
258+
temp_file = f.name
259+
260+
try:
261+
# Should not raise TypeError when dependencies is None
262+
result = get_processing_code_hash(code=temp_file, source_dir=None, dependencies=None)
263+
264+
assert result is not None
265+
assert len(result) == 64
266+
finally:
267+
os.unlink(temp_file)
268+
269+
def test_get_processing_code_hash_with_none_dependencies_and_source_dir(self):
270+
"""Test get_processing_code_hash with source_dir and None dependencies"""
271+
with tempfile.TemporaryDirectory() as temp_dir:
272+
code_file = Path(temp_dir, "script.py")
273+
code_file.write_text("print('hello')")
274+
275+
# Should not raise TypeError when dependencies is None
276+
result = get_processing_code_hash(
277+
code=str(code_file), source_dir=temp_dir, dependencies=None
278+
)
279+
280+
assert result is not None
281+
assert len(result) == 64
253282
"""Test get_processing_code_hash with dependencies"""
254283
with tempfile.TemporaryDirectory() as temp_dir:
255284
code_file = Path(temp_dir, "script.py")
@@ -317,6 +346,35 @@ def test_get_training_code_hash_s3_uri(self):
317346
assert result is None
318347

319348
def test_get_training_code_hash_pipeline_variable(self):
349+
350+
def test_get_training_code_hash_with_none_dependencies_source_dir(self):
351+
"""Test get_training_code_hash with source_dir and None dependencies does not raise"""
352+
with tempfile.TemporaryDirectory() as temp_dir:
353+
entry_file = Path(temp_dir, "train.py")
354+
entry_file.write_text("print('training')")
355+
356+
result = get_training_code_hash(
357+
entry_point=str(entry_file), source_dir=temp_dir, dependencies=None
358+
)
359+
360+
assert result is not None
361+
assert len(result) == 64
362+
363+
def test_get_training_code_hash_with_none_dependencies_entry_point_only(self):
364+
"""Test get_training_code_hash with entry_point only and None dependencies"""
365+
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
366+
f.write("print('training')")
367+
temp_file = f.name
368+
369+
try:
370+
result = get_training_code_hash(
371+
entry_point=temp_file, source_dir=None, dependencies=None
372+
)
373+
374+
assert result is not None
375+
assert len(result) == 64
376+
finally:
377+
os.unlink(temp_file)
320378
"""Test get_training_code_hash with pipeline variable returns None"""
321379
with patch("sagemaker.core.workflow.is_pipeline_variable", return_value=True):
322380
result = get_training_code_hash(

0 commit comments

Comments
 (0)