Skip to content

Attempting to serialize bytes type causes error #5660

Closed

Description

@ava-harris

PySDK Version

  • PySDK V2 (2.x)
  • PySDK V3 (3.x)

Describe the bug
When attempting to call the invoke function with a bytes object in the body, it throws an error during serialization. This is because bytes are not treated as a primitive.

elif is_not_primitive(value):
# if the value is a dict, use _serialize_shape() to serialize it recursively
return _serialize_shape(value)
else:
return value

def is_not_primitive(obj):
return not isinstance(obj, (int, float, str, bool, datetime.datetime))

To reproduce

from sagemaker.core.utils.utils import serialize
serialize({"body": b'1'})

Expected behavior

{'body': b'1'}

Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.

Image Image Image

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: 3.6.0
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): N/A
  • Framework version: N/A
  • Python version: 3.12.9
  • CPU or GPU: N/A
  • Custom Docker image (Y/N): N

Additional context
Add any other context about the problem here.

Activity

  1. changed the title [-]attempting to serialize bytes type causes Error[/-] [+]Attempting to serialize bytes type causes error[/+] on Mar 20, 2026
  2. mohamedzeidan2021 commented on Sep 1, 2026

    @mohamedzeidan2021
    Collaborator

    Fixed in #5736, released in v3.11.0. bytes is now treated as a primitive in the serializer (is_not_primitive includes bytes), so serialize({"body": b'1'}) returns {'body': b'1'} as expected — verified against your repro. You were on 3.6.0, which predates the fix; please upgrade to v3.11.0 or later. Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions