Skip to content

fix: Pipeline TypeError: can only concatenate list (not "NoneType") to list Using Sou (#5518)#15

Closed
aviruthen wants to merge 1 commit intomasterfrom
fix/pipeline-typeerror-can-only-concatenate-list-not-5518
Closed

fix: Pipeline TypeError: can only concatenate list (not "NoneType") to list Using Sou (#5518)#15
aviruthen wants to merge 1 commit intomasterfrom
fix/pipeline-typeerror-can-only-concatenate-list-not-5518

Conversation

@aviruthen
Copy link
Copy Markdown
Owner

Description

Fix TypeError when TrainingStep's SourceCode has requirements=None

Problem

When creating a TrainingStep with a SourceCode object that doesn't specify requirements (defaulting to None), the pipeline compilation fails with a TypeError because get_training_code_hash() attempts list concatenation with None:

TypeError: can only concatenate list (not "NoneType") to list

This occurs in get_code_hash() which passes source_code.requirements (which is None) directly to get_training_code_hash() as the dependencies parameter.

Fix

  1. get_code_hash(): Normalize source_code.requirements using or None to ensure falsy values (empty strings, empty lists, etc.) are converted to None before being passed downstream.

  2. get_training_code_hash(): Added a defensive type check at the top of the function that validates dependencies is either None or a str. If an unexpected type is passed (e.g., a list), it logs a warning and sets dependencies to None to prevent TypeError from list concatenation.

Testing

  • Added test_get_training_code_hash_with_none_dependencies - verifies None dependencies with source_dir works
  • Added test_get_training_code_hash_with_none_dependencies_entry_point_only - verifies None dependencies with entry_point only works
  • Added test_get_training_code_hash_with_non_string_dependencies - verifies non-string dependencies are handled gracefully
  • Added integration-style tests for get_code_hash with mocked TrainingStep objects having requirements=None

Related Issue

Fixes aws#5518

Changes Made

The bug occurs in get_code_hash() in sagemaker-core/src/sagemaker/core/workflow/utilities.py when processing a TrainingStep whose SourceCode object has requirements=None (the default when not specified). The get_code_hash() function extracts source_code.requirements (which is None) and passes it to get_training_code_hash() as the dependencies parameter. The get_training_code_hash() function already has if dependencies: guards in the current codebase, which correctly handles None. However, the issue reporter on v3.3.1 encountered a version where the code directly concatenated [source_dir] + dependencies without checking for None first. The current code in the repo appears to have the fix with if dependencies: guards, but there's still a defensive improvement needed: the get_code_hash() function should normalize None requirements to avoid passing None downstream, and the type hint for dependencies in get_training_code_hash should accept Optional[str] (which it already does). The fix should also add a fallback or expression in get_code_hash to convert None to a safe default, making the code more robust.

AI-Generated PR

This PR was automatically generated by the PySDK Issue Agent.

  • Confidence score: 88%
  • Classification: bug
  • SDK version target: V3

Merge Checklist

  • Changes are backward compatible
  • Commit message follows prefix: description format
  • Unit tests added/updated
  • Integration tests added (if applicable)
  • Documentation updated (if applicable)

@aviruthen aviruthen closed this Mar 20, 2026
@aviruthen aviruthen deleted the fix/pipeline-typeerror-can-only-concatenate-list-not-5518 branch March 20, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pipeline TypeError: can only concatenate list (not "NoneType") to list Using SourceCode

1 participant