cloudpipe / cloudpipe/cloudpickle
Incorrect deserialization of subclasses, module changed to `types`
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 1
Description
This issue is similar to #440 but I have verified it still happens after the fix (on latest master).
Somehow the deserialized subclass has `__module__` of `types` instead of `__main__`. This also happen when the classes are moved to their separate files.
See the following repro script:
```python
import cloudpickle
import multiprocessing as mp
print(cloudpickle.__version__)
class Parent:
pass
class Child(Parent):
pass
def get_mro(klass):
return [f"{base.__module__}.{base.__qualname__}" for base in klass.mro()]
def task(b: bytes):
cls = cloudpickle.loads(b)
return str(cls), get_mro(cls)
for klass in [Parent, Child]:
with mp.Pool() as pool:
cls_name, mros = pool.apply(task, (cloudpickle.dumps(klass),))
print()
print("local class name", str(klass))
print("deserialized class name", cls_name)
print()
print("local mro", get_mro(klass))
print("deserialized mro", mros)
```
My output on Python 3.7 f758eb34d1b3285dc582b73bfd8df4c47ed4fc68
```
2.1.0.dev0
local class name
deserialized class name
local mro ['__main__.Parent', 'builtins.object']
deserialized mro ['__main__.Parent', 'builtins.object']
local class name
deserialized class name
local mro ['__main__.Child', '__main__.Parent', 'builtins.object']
deserialized mro ['types.Child', '__main__.Parent', 'builtins.object']
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.