Conversation
…o list Using Sou (aws#5518)
aviruthen
left a comment
There was a problem hiding this comment.
🤖 AI Code Review
The fix addresses a real bug where dependencies=None causes a TypeError in get_processing_code_hash(), but the diff appears to have a critical issue — the if source_dir: guard was removed, which would break the function's control flow. The tests are well-structured and cover the relevant cases.
| @@ -211,7 +211,9 @@ def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str] | |||
| """ | |||
|
|
|||
| # FrameworkProcessor | |||
There was a problem hiding this comment.
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.
| assert result is not None | ||
| assert len(result) == 64 | ||
|
|
||
| def test_get_processing_code_hash_code_only_with_none_dependencies(self): |
There was a problem hiding this comment.
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.
Description
Fix TypeError when dependencies is None in get_processing_code_hash
Fixes aws#5518
Problem
When
dependenciesis passed asNonetoget_processing_code_hash(), the function attempts to concatenate a list withNone(e.g.,[code, source_dir] + dependencies), which raises:The same pattern was already fixed in
get_training_code_hash()withif dependencies:guards, butget_processing_code_hash()was left unprotected.Solution
Added a defensive
dependencies = dependencies or []at the start ofget_processing_code_hash()to normalizeNoneto an empty list before any list concatenation occurs.Testing
Added two new test cases:
test_get_processing_code_hash_with_none_dependencies— verifies no TypeError when source_dir is provided withdependencies=Nonetest_get_processing_code_hash_code_only_with_none_dependencies— verifies no TypeError when only code is provided withdependencies=NoneExisting tests for
get_training_code_hashwithdependencies=Nonecontinue to pass.Related Issue
Fixes aws#5518
Changes Made
The bug occurs when
SourceCode.requirementsis not set (defaults toNone), and the pipeline'sget_code_hash()function passes thisNonevalue asdependenciestoget_training_code_hash(). In the released v3.3.1,get_training_code_hash()directly concatenates[source_dir] + dependencieswhich fails withTypeError: can only concatenate list (not 'NoneType') to list. The fix in the current repo already guards this withif dependencies:checks inget_training_code_hash(). However,get_processing_code_hash()has the same fragile pattern — it directly concatenates+ dependencieswithout aNoneguard, relying on the caller to always pass a list. This should also be hardened with a defensive default.AI-Generated PR
This PR was automatically generated by the PySDK Issue Agent.
Merge Checklist
prefix: descriptionformat