'B64decode and unpickle the object, optionally decompressing it.
If an error is raised in de-pickling and we\'re sure the value is
a definite pickle, the error is allowed to propagate. If we
aren\'t sure if the value is a pickle or not, then we catch the
error and return the original value instead.'

def from_db_value(self, value, *args):

    if (value is not None):
        try:
            value = dbsafe_decode(value, self.compress)
        except Exception:
            if isinstance(value, PickledObject):
                raise
        else:
            if isinstance(value, _ObjectWrapper):
                return value._obj
    return value
