diff --git a/sagemaker-core/src/sagemaker/core/workflow/utilities.py b/sagemaker-core/src/sagemaker/core/workflow/utilities.py index c07a31c51e..a74ce0c6d9 100644 --- a/sagemaker-core/src/sagemaker/core/workflow/utilities.py +++ b/sagemaker-core/src/sagemaker/core/workflow/utilities.py @@ -210,6 +210,9 @@ def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str] str: A hash string representing the unique code artifact(s) for the step """ + dependencies = dependencies or [] + + # FrameworkProcessor if source_dir: source_dir_url = urlparse(source_dir) @@ -245,6 +248,9 @@ def get_training_code_hash( Returns: str: A hash string representing the unique code artifact(s) for the step """ + dependencies = dependencies or [] + + from sagemaker.core.workflow import is_pipeline_variable if not is_pipeline_variable(source_dir) and not is_pipeline_variable(entry_point): diff --git a/sagemaker-core/tests/unit/workflow/test_utilities.py b/sagemaker-core/tests/unit/workflow/test_utilities.py index 5e9ed7bbbd..e6541b155c 100644 --- a/sagemaker-core/tests/unit/workflow/test_utilities.py +++ b/sagemaker-core/tests/unit/workflow/test_utilities.py @@ -325,6 +325,64 @@ def test_get_training_code_hash_pipeline_variable(self): assert result is None + def test_get_training_code_hash_with_none_dependencies_source_dir(self): + """Test get_training_code_hash with source_dir and dependencies=None does not raise TypeError""" + with tempfile.TemporaryDirectory() as temp_dir: + entry_file = Path(temp_dir, "train.py") + entry_file.write_text("print('training')") + + result = get_training_code_hash( + entry_point=str(entry_file), source_dir=temp_dir, dependencies=None + ) + + assert result is not None + assert len(result) == 64 + + def test_get_training_code_hash_with_entry_point_only_and_none_dependencies(self): + """Test get_training_code_hash with entry_point only and dependencies=None returns valid hash""" + with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f: + f.write("print('training')") + temp_file = f.name + + try: + result = get_training_code_hash( + entry_point=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_none_dependencies_source_dir(self): + """Test get_processing_code_hash with source_dir and dependencies=None 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_with_none_dependencies_code_only(self): + """Test get_processing_code_hash with code only and dependencies=None does not raise TypeError""" + 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_validate_step_args_input_valid(self): """Test validate_step_args_input with valid input""" step_args = _StepArguments(