googleapis/python-ndb

PickleProperty put in Python 2.7 GAE NDB cannot be loaded by Cloud NDB on Python 3

crwilcox opened this issue · 1 comments

Discovered while working to repro #587

https://github.com/googleapis/python-ndb/blob/master/google/cloud/ndb/model.py#L2923

The data written in python 2.7 is of type bytes, but the code as written asumes a string. We could validate input types to do the right thing, possibly:

def _from_base_type(self, value):
        """Convert a value from the "base" value type for this property.

        Args:
            value (bytes): The value to be converted.

        Returns:
            Any: The unpickled ``value``.
        """
        if type(value) is bytes:
            return pickle.loads(value, encoding="bytes")
        return pickle.loads(value)

Closed by #596