Skip to content

fix: Invalid import (5637)#5686

Draft
aviruthen wants to merge 3 commits intoaws:masterfrom
aviruthen:fix/invalid-import-5637
Draft

fix: Invalid import (5637)#5686
aviruthen wants to merge 3 commits intoaws:masterfrom
aviruthen:fix/invalid-import-5637

Conversation

@aviruthen
Copy link
Collaborator

Description

The file sagemaker-mlops/src/sagemaker/mlops/workflow/steps.py has an invalid import at line 208 inside the _find_dependencies_in_step_arguments method. It imports DelayedReturn from sagemaker.core.workflow.function_step, but that module does not exist in the sagemaker-core package (there is no function_step.py in sagemaker-core/src/sagemaker/core/workflow/). The DelayedReturn class is actually defined in sagemaker-mlops/src/sagemaker/mlops/workflow/function_step.py, so the import should be from sagemaker.mlops.workflow.function_step import DelayedReturn.

Related Issue

Fixes GitHub issue 5637

Changes Made

  • sagemaker-mlops/src/sagemaker/mlops/workflow/steps.py
  • sagemaker-mlops/tests/unit/workflow/test_steps.py

AI-Generated PR

This PR was automatically generated by the PySDK Issue Agent.

  • Confidence score: 85%
  • 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)

Copy link
Collaborator

@sagemaker-bot sagemaker-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review

The fix correctly changes the import path for DelayedReturn from the non-existent sagemaker.core.workflow.function_step to the correct sagemaker.mlops.workflow.function_step. However, the test file has several issues: a duplicate function body in test_step_find_dependencies_in_step_arguments_with_delayed_return, trailing whitespace, and some tests that don't actually exercise the code path they claim to test.

Step._validate_json_get_function(step, json_get, step_map)


def test_delayed_return_import_from_correct_module():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low-value test. This test (test_delayed_return_import_from_correct_module) only verifies that the import statement works, which is already implicitly tested by the other tests that import and use DelayedReturn. Consider removing it — the real value is in testing that _find_dependencies_in_step_arguments works correctly with the fixed import, which the other tests cover.

assert isinstance(DelayedReturn, type)


def test_find_dependencies_in_step_arguments_with_delayed_return_uses_correct_import():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test doesn't exercise the fix. test_find_dependencies_in_step_arguments_with_delayed_return_uses_correct_import creates mocks and asserts isinstance(delayed, DelayedReturn), but it never calls _find_dependencies_in_step_arguments. The isinstance check on a Mock(spec=DelayedReturn) will always pass regardless of where DelayedReturn is imported from. This test doesn't actually verify the bug fix. Consider removing it in favor of the more comprehensive test at line 447 that actually calls the method.

@@ -450,6 +510,7 @@ def test_step_find_dependencies_in_step_arguments_with_delayed_return():
assert "step1" in dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. There's a double blank line here. PEP 8 expects one blank line between methods inside a test module at this level.

Copy link
Collaborator

@sagemaker-bot sagemaker-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review

This PR fixes a genuine bug where DelayedReturn was imported from a non-existent module path (sagemaker.core.workflow.function_step) and corrects it to the actual location (sagemaker.mlops.workflow.function_step). The fix is minimal and correct. The test changes appropriately simplify tests by removing unnecessary mocking of the broken import path. However, there are some issues with the test file changes.

Step._validate_json_get_function(step, json_get, step_map)



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are ~30 lines of seemingly orphaned code between test_step_validate_json_get_function_with_property_file and test_step_find_dependencies_in_step_arguments_with_json_get that contain bare import statements (from sagemaker.mlops.workflow.steps import Step, StepTypeEnum and from sagemaker.core.workflow.functions import JsonGet) outside of any function or class definition. These imports execute at module load time and appear to be leftover from an incomplete edit. They should either be placed inside a proper test function or removed entirely. As-is, they are dead code that will execute on import and could mask import errors.

with patch.dict('sys.modules', {'sagemaker.core.workflow.function_step': Mock()}):
dependencies = Step._find_dependencies_in_step_arguments(step2, obj, {"step1": step1})
assert "step1" in dependencies
dependencies = Step._find_dependencies_in_step_arguments(step2, obj, {"step1": step1})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement — removing the patch.dict('sys.modules', ...) workaround now that the import path is fixed. The test is much cleaner and actually validates the real import path works correctly.


def test_step_find_dependencies_in_step_arguments_with_delayed_return():
from unittest.mock import patch
from sagemaker.mlops.workflow.steps import Step, StepTypeEnum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good: directly importing DelayedReturn from the corrected path and using Mock(spec=DelayedReturn) is much better than the previous approach of dynamically creating a fake class. This properly validates that the import works and that the isinstance check in the source code will function correctly.

dependencies.add(self._get_step_name_from_str(referenced_step, step_map))

from sagemaker.core.workflow.function_step import DelayedReturn
from sagemaker.mlops.workflow.function_step import DelayedReturn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct. The DelayedReturn class lives in sagemaker.mlops.workflow.function_step, not sagemaker.core.workflow.function_step. This is a lazy import (inside the method) which is appropriate here to avoid circular imports between steps.py and function_step.py.

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.

2 participants