cloudpipe / cloudpipe/cloudpickle

Pickle by value datetime dependency

Open
#516 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
1

Description

Hi folks,

I've came across a behavior which I cannot explain. I am not sure if this is a bug or a limitation or simply I am am not using cloudpickle correctly. My hope is we can clarify which one it is. I am trying to pickle by value an object and its dependencies. In this case I am using a datetime as a dependency. The result is an error: `AttributeError: type object 'date' has no attribute '__add__'`

In order to reproduce this you can use the following test case(I am using Python 3.8), which is a simplified version.
```

def test_pickle_by_value_datetime_dependency(self):

_prev_sys_path = sys.path.copy()
try:
_mock_interactive_session_cwd = os.path.dirname(__file__)

_maybe_remove(sys.path, '')
_maybe_remove(sys.path, _mock_interactive_session_cwd)

sys.path.insert(0, _mock_interactive_session_cwd)

with subprocess_worker(protocol=self.protocol) as w:
w.run(
lambda p: sys.path.remove(p), _mock_interactive_session_cwd
)

class C:
def __init__(self, d):
self.d = d

cloudpickle.register_pickle_by_value(__import__(C.__module__))
cloudpickle.register_pickle_by_value(datetime)

d = datetime.datetime.now()
obj = C(d)

dump = cloudpickle.dumps(obj)

w.run(
lambda content: cloudpickle.loads(content), dump
)
finally:
sys.path = _prev_sys_path
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.