Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sagemaker-core/src/sagemaker/core/telemetry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Feature(Enum):
MODEL_TRAINER = 14
MODEL_CUSTOMIZATION = 15
MLOPS = 16
FEATURE_STORE = 17

def __str__(self): # pylint: disable=E0307
"""Return the feature name."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
str(Feature.MODEL_TRAINER): 14,
str(Feature.MODEL_CUSTOMIZATION): 15,
str(Feature.MLOPS): 16,
str(Feature.FEATURE_STORE): 17,
}

STATUS_TO_CODE = {
Expand All @@ -81,6 +82,9 @@ def wrapper(*args, **kwargs):
if len(args) > 0 and hasattr(args[0], "sagemaker_session"):
# Get the sagemaker_session from the instance method args
sagemaker_session = args[0].sagemaker_session
elif len(args) > 0 and hasattr(args[0], "_sagemaker_session"):
# Get the sagemaker_session from the instance method args (private attribute)
sagemaker_session = args[0]._sagemaker_session
elif feature == Feature.REMOTE_FUNCTION:
# Get the sagemaker_session from the function keyword arguments for remote function
sagemaker_session = kwargs.get(
Expand Down
16 changes: 16 additions & 0 deletions sagemaker-core/src/sagemaker/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@ def __new__(cls):
cls._instance = super().__new__(cls)
return cls._instance

def __repr__(self):
"""Return clean representation for debugging."""
return "Unassigned()"

def __str__(self):
"""Return empty string for clean printing."""
return ""

def __iter__(self):
"""Return empty iterator to prevent iteration errors."""
return iter([])

def __bool__(self):
"""Return False for truthiness checks."""
return False


class SingletonMeta(type):
"""
Expand Down
47 changes: 47 additions & 0 deletions sagemaker-core/tests/unit/generated/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,50 @@ def test_serialize_method_nested_shape():
"StringValue": "string",
},
}


class TestUnassignedBehavior:
"""Test Unassigned class methods for proper behavior.

Bug fix: GetRecordResponse is not printable and cannot be parsed via iterator.
Error: TypeError: 'Unassigned' object is not iterable
"""

def test_unassigned_repr(self):
"""Test that Unassigned has clean repr."""
u = Unassigned()
assert repr(u) == "Unassigned()"

def test_unassigned_str(self):
"""Test that Unassigned converts to empty string."""
u = Unassigned()
assert str(u) == ""

def test_unassigned_bool(self):
"""Test that Unassigned is falsy."""
u = Unassigned()
assert not u
assert bool(u) is False

def test_unassigned_iter(self):
"""Test that Unassigned is iterable and returns empty list."""
u = Unassigned()
result = list(u)
assert result == []

def test_unassigned_singleton(self):
"""Test that Unassigned is a singleton."""
u1 = Unassigned()
u2 = Unassigned()
assert u1 is u2

def test_unassigned_in_conditional(self):
"""Test that Unassigned works correctly in conditionals."""
u = Unassigned()

# Should evaluate to False
if u:
pytest.fail("Unassigned should be falsy")

# Should work with not
assert not u
Loading
Loading