Skip to content

Commit 1b80f49

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

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def get_code_hash(step: Entity) -> str:
173173
source_code = model_trainer.source_code
174174
if source_code:
175175
source_dir = source_code.source_dir
176+
# requirements may be None when SourceCode.requirements is not set;
177+
# get_training_code_hash handles None dependencies gracefully
176178
requirements = source_code.requirements
177179
entry_point = source_code.entry_script
178180
return get_training_code_hash(entry_point, source_dir, requirements)
@@ -197,6 +199,7 @@ def get_processing_dependencies(dependency_args: List[List[str]]) -> List[str]:
197199

198200

199201
def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str]) -> str:
202+
dependencies = dependencies or []
200203
"""Get the hash of a processing step's code artifact(s).
201204
202205
Args:

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,35 @@ def test_get_processing_dependencies_multiple_lists(self):
214214

215215
assert result == ["dep1", "dep2", "dep3", "dep4", "dep5"]
216216

217+
def test_get_processing_code_hash_with_none_dependencies(self):
218+
"""Test get_processing_code_hash does not raise TypeError when dependencies is None"""
219+
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
220+
f.write("print('hello')")
221+
temp_file = f.name
222+
223+
try:
224+
# Should not raise TypeError
225+
result = get_processing_code_hash(code=temp_file, source_dir=None, dependencies=None)
226+
227+
assert result is not None
228+
assert len(result) == 64
229+
finally:
230+
os.unlink(temp_file)
231+
232+
def test_get_processing_code_hash_with_none_dependencies_and_source_dir(self):
233+
"""Test get_processing_code_hash with source_dir and None dependencies"""
234+
with tempfile.TemporaryDirectory() as temp_dir:
235+
code_file = Path(temp_dir, "script.py")
236+
code_file.write_text("print('hello')")
237+
238+
# Should not raise TypeError
239+
result = get_processing_code_hash(
240+
code=str(code_file), source_dir=temp_dir, dependencies=None
241+
)
242+
243+
assert result is not None
244+
assert len(result) == 64
245+
217246
def test_get_processing_code_hash_with_source_dir(self):
218247
"""Test get_processing_code_hash with source_dir"""
219248
with tempfile.TemporaryDirectory() as temp_dir:
@@ -264,6 +293,34 @@ def test_get_processing_code_hash_with_dependencies(self):
264293

265294
assert result is not None
266295

296+
def test_get_training_code_hash_with_none_dependencies_and_source_dir(self):
297+
"""Test get_training_code_hash with source_dir and None dependencies does not raise"""
298+
with tempfile.TemporaryDirectory() as temp_dir:
299+
entry_file = Path(temp_dir, "train.py")
300+
entry_file.write_text("print('training')")
301+
302+
# Should not raise TypeError
303+
result = get_training_code_hash(
304+
entry_point=str(entry_file), source_dir=temp_dir, dependencies=None
305+
)
306+
307+
assert result is not None
308+
assert len(result) == 64
309+
310+
def test_get_training_code_hash_with_none_dependencies_and_entry_point(self):
311+
"""Test get_training_code_hash with entry_point only and None dependencies does not raise"""
312+
with tempfile.TemporaryDirectory() as temp_dir:
313+
entry_file = Path(temp_dir, "train.py")
314+
entry_file.write_text("print('training')")
315+
316+
# Should not raise TypeError
317+
result = get_training_code_hash(
318+
entry_point=str(entry_file), source_dir=None, dependencies=None
319+
)
320+
321+
assert result is not None
322+
assert len(result) == 64
323+
267324
def test_get_training_code_hash_with_source_dir(self):
268325
"""Test get_training_code_hash with source_dir"""
269326
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)