Skip to content

Commit 0fce373

Browse files
committed
fix: Attempting to serialize bytes type causes error (5660)
1 parent ee420cc commit 0fce373

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

sagemaker-core/src/sagemaker/core/utils/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def pascal_to_snake(pascal_str):
273273

274274

275275
def is_not_primitive(obj):
276-
return not isinstance(obj, (int, float, str, bool, datetime.datetime))
276+
return not isinstance(obj, (int, float, str, bool, bytes, datetime.datetime))
277277

278278

279279
def is_not_str_dict(obj):
@@ -285,7 +285,7 @@ def is_primitive_list(obj):
285285

286286

287287
def is_primitive_class(cls):
288-
return cls in (str, int, bool, float, datetime.datetime)
288+
return cls in (str, int, bool, float, bytes, datetime.datetime)
289289

290290

291291
class Unassigned:

sagemaker-core/tests/unit/generated/test_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,30 @@ def test_serialize_method_nested_shape():
373373
}
374374

375375

376+
377+
def test_serialize_with_bytes_value_returns_bytes():
378+
result = serialize(b'1')
379+
assert result == b'1'
380+
381+
382+
def test_serialize_dict_with_bytes_value_returns_dict_with_bytes():
383+
result = serialize({'body': b'1'})
384+
assert result == {'body': b'1'}
385+
386+
387+
def test_is_not_primitive_with_bytes_returns_false():
388+
assert is_not_primitive(b'hello') is False
389+
390+
391+
def test_is_primitive_class_with_bytes_returns_true():
392+
assert is_primitive_class(bytes) is True
393+
394+
395+
def test_serialize_list_with_bytes_elements():
396+
result = serialize([b'a', b'b'])
397+
assert result == [b'a', b'b']
398+
399+
376400
class TestUnassignedBehavior:
377401
"""Test Unassigned class methods for proper behavior.
378402

0 commit comments

Comments
 (0)