Skip to content

fix: Attempting to serialize bytes type causes error (5660)#5682

Closed
aviruthen wants to merge 2 commits intoaws:masterfrom
aviruthen:fix/attempting-to-serialize-bytes-type-causes-error-5660
Closed

fix: Attempting to serialize bytes type causes error (5660)#5682
aviruthen wants to merge 2 commits intoaws:masterfrom
aviruthen:fix/attempting-to-serialize-bytes-type-causes-error-5660

Conversation

@aviruthen
Copy link
Copy Markdown
Collaborator

Description

The bytes type is not included in the primitive type checks in sagemaker-core/src/sagemaker/core/utils/utils.py. When serialize() encounters a bytes object, is_not_primitive() returns True (since bytes isn't in the primitive tuple), causing the code to fall through to _serialize_shape(), which calls vars() on the bytes object and raises a TypeError. The fix is to add bytes to both is_not_primitive() and is_primitive_class() functions.

Related Issue

Fixes GitHub issue 5660

Changes Made

  • sagemaker-core/src/sagemaker/core/utils/utils.py
  • sagemaker-core/tests/unit/generated/test_utils.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
Copy Markdown
Member

@mufaddal-rohawala mufaddal-rohawala 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 legitimate bug where bytes objects cause a TypeError during serialization. The fix is correct and minimal, and the tests are well-structured. However, there is an indentation issue in the source code changes that must be fixed before merging.


def is_not_primitive(obj):
return not isinstance(obj, (int, float, str, bool, datetime.datetime))
return not isinstance(obj, (int, float, str, bool, bytes, datetime.datetime))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bug: Incorrect indentation introduced. The return statement now has 8 spaces of indentation (two levels) instead of the original 4 spaces (one level). This will cause an IndentationError at runtime since the function body was previously at 4-space indentation. Please fix:

    return not isinstance(obj, (int, float, str, bool, bytes, datetime.datetime))


def is_primitive_class(cls):
return cls in (str, int, bool, float, datetime.datetime)
return cls in (str, int, bool, float, bytes, datetime.datetime)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bug: Same incorrect indentation issue here. The return statement has 8 spaces instead of 4. Please fix:

    return cls in (str, int, bool, float, bytes, datetime.datetime)

@@ -373,6 +373,30 @@ def test_serialize_method_nested_shape():
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: There's an extra blank line here (two blank lines between the previous test and this one, resulting in three blank lines total between top-level definitions). PEP 8 specifies two blank lines between top-level definitions. Minor, but CI linting may flag it.

@aviruthen aviruthen closed this Mar 26, 2026
@aviruthen aviruthen deleted the fix/attempting-to-serialize-bytes-type-causes-error-5660 branch March 26, 2026 17:50
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