Skip to content

Commit 88f910d

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

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,31 @@ 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_empty_bytes_returns_empty_dict():
383+
# Empty bytes is falsy, so the walrus operator in _serialize_dict skips it
384+
result = serialize({"body": b""})
385+
assert result == {}
386+
387+
388+
def test_serialize_with_bytes_in_list():
389+
result = serialize([b"hello", b"world"])
390+
assert result == [b"hello", b"world"]
391+
392+
393+
def test_is_not_primitive_with_bytes_returns_false():
394+
assert is_not_primitive(b"test") is False
395+
396+
397+
def test_is_primitive_class_with_bytes_returns_true():
398+
assert is_primitive_class(bytes) is True
399+
400+
376401
class TestUnassignedBehavior:
377402
"""Test Unassigned class methods for proper behavior.
378403

0 commit comments

Comments
 (0)