Skip to content

Commit ddcda3e

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

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,25 @@ def test_serialize_method_nested_shape():
373373
}
374374

375375

376+
377+
def test_serialize_with_bytes_value_returns_bytes():
378+
result = serialize({'body': b'1'})
379+
assert result == {'body': b'1'}
380+
381+
382+
def test_serialize_with_bytes_in_list():
383+
result = serialize([b'hello', b'world'])
384+
assert result == [b'hello', b'world']
385+
386+
387+
def test_is_not_primitive_with_bytes_returns_false():
388+
assert is_not_primitive(b'test') is False
389+
390+
391+
def test_is_primitive_class_with_bytes_returns_true():
392+
assert is_primitive_class(bytes) is True
393+
394+
376395
class TestUnassignedBehavior:
377396
"""Test Unassigned class methods for proper behavior.
378397

0 commit comments

Comments
 (0)