You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When restoring a value of a dataclass with cloudpickle, it breaks:
Example
import dataclasses
from dataclasses import dataclass
@dataclass
class Range:
start: int
end: int
v = Range(1, 2)
print("defined")
print(dataclasses.fields(v))
import cloudpickle
print("imported cloudpickle")
print(dataclasses.fields(v))
v_dumped = cloudpickle.dumps(v)
print("dumped with cloudpickle")
print(dataclasses.fields(v))
vv = cloudpickle.loads(v_dumped)
print("loaded with cloudpickle")
print(dataclasses.fields(v))
print("restored value")
print(dataclasses.fields(vv))
Leads to
defined
(Field(name='start',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='end',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
imported cloudpickle
(Field(name='start',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='end',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
dumped with cloudpickle
(Field(name='start',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='end',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object at 0x109634ca0>,default_factory=<dataclasses._MISSING_TYPE object at 0x109634ca0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))
loaded with cloudpickle
()
restored value
()
I.e. as soon as we restore, the type of the data class is destroyed
The text was updated successfully, but these errors were encountered:
I came here as a user with a different issue, but iirc pickles were never self-describing; they always needed the definitions for non-standard-library types to deserialize correctly. So if you dump the data from a script, the pickle doesn't record a real location from whence the type came, since it was never imported, just defined in the interpreter. Then the deserializer has nothing to import to reconstruct the type.
When restoring a value of a
dataclass
with cloudpickle, it breaks:Example
Leads to
I.e. as soon as we restore, the type of the data class is destroyed
The text was updated successfully, but these errors were encountered: