Skip to content

Conversation

@markhsu-ms
Copy link
Contributor

Change Summary

  • Make Pickle serializer customizable so that user can overwrite dumps and loads behavior to support different data formate. It will be very useful when dealing with Py2 Py3 compatibility issue.

Highlight of Code Change

  • Add DefaultSerializer with default pickling behavior
  • Read TRANSMISSION_SERIALIZER from Django config setting, and then use the user provided serializer if class exists.

Code Sample

Create custom serializer class. Serializer must contains dumps and loads methods

# project/lib/django/serializer.py

import pickle

class CustomSerializer(object):
    def dumps(self, value):
        return pickle.dumps(value, 2)

    def loads(self, value):
        return pickle.loads(value, fix_imports=True, encoding="latin1")

Set TRANSMISSION_SERIALIZER with serializer path

# project/config/common/settings.py

TRANSMISSION_SERIALIZER = "lib.django.serializer.CustomSerializer"

@shortcut-integration
Copy link

This pull request has been linked to Clubhouse Story #63930: Python 3 transmissions library update.

@markhsu-ms markhsu-ms changed the title feat: Add serializer config to load and dump Pickle data feat: Add config to support Pickle serializer customization Jun 2, 2021
@markhsu-ms markhsu-ms requested review from JamieCzuy, karljin and manav June 2, 2021 21:11
Copy link
Contributor

@manav manav left a comment

Choose a reason for hiding this comment

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

Looks good. we should also create a new tag.

@markhsu-ms markhsu-ms merged commit bd0972f into master Jun 3, 2021
@markhsu-ms markhsu-ms deleted the markhsu/ch63930/python-3-transmissions-library-update branch June 3, 2021 03:59
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.

3 participants