Skip to content

Commit

Permalink
Support python27 pickle by converting str to bytes. (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrellis authored May 26, 2023
1 parent ad6e5cc commit bebbdec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/google/appengine/ext/ndb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3043,7 +3043,16 @@ def __get_arg(cls, kwds, kwd):
def __getstate__(self):
return self._to_pb().SerializeToString()

def _py2_compat_encode(self, py2_serialized_pb):
return bytes(py2_serialized_pb, 'latin1')

def __setstate__(self, serialized_pb):
if isinstance(serialized_pb, str):
# If 'serialized_pb' was written by a python27 clone.
logging.warning(
'Assuming python2 pickled state, converting to python3 type.'
)
serialized_pb = self._py2_compat_encode(serialized_pb)
pb = entity_pb2.EntityProto.FromString(serialized_pb)
self.__init__()
self.__class__._from_pb(pb, set_key=False, ent=self)
Expand Down

0 comments on commit bebbdec

Please sign in to comment.