Skip to content

Override attributes are not pickled correctly #584

@roysh-jether

Description

@roysh-jether

When you have parent and child classes both have the same attribute, then the __dict__ of each class should contains this attribute.
But when the attribute have the same value, cloudpickle will remove the attribute from the dict of the sub class.

For Example:

import cloudpickle
import gc

class A:
    __version__ = 1

class B(A):
    __version__ = 1


obj = B()
print('Obj: ', '__version__' in obj.__class__.__dict__)

s = cloudpickle.dumps(obj)

loaded_obj = cloudpickle.loads(s)

print('Loaded obj: ', '__version__' in loaded_obj.__class__.__dict__)

del A
del B
del obj
del loaded_obj
gc.collect()

loaded_obj = cloudpickle.loads(s)

print('Loaded obj after gc: ', '__version__' in loaded_obj.__class__.__dict__)

The output will be:

Obj:  True
Loaded obj:  True
Loaded obj after gc:  False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions