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
Bug Description
Pickling tagge_union type is not working because __dataclass_fields__ is set on the object's __dict__ instead of the class __dict__. Additionally, __dataclass_fields__ cannot be pickled automatically since it contains a mappingproxy.
Expected Behavior
The Option type should be pickled successfully without errors.
Code Example
Below is a minimal code example to illustrate the issue:
importpicklefromexpressionimportSomeobj=Some(1)
# Attempt to pickle the objecttry:
pickled_obj=pickle.dumps(obj)
unpickled_obj=pickle.loads(pickled_obj)
print("Pickling and unpickling successful.")
exceptExceptionase:
print(f"Error during pickling: {e}")
Additional Context
The issue arises because __dataclass_fields__ is set on the instance's __dict__ rather than the class's __dict__.
__dataclass_field__ contains a mappingproxy, which cannot be pickled automatically.
Environment
Pydantic version: 5.0.2
Error Message
If applicable, include the error message you encountered:
Error during pickling: can't pickle 'mappingproxy' object
Potential Solution
Implement __setstate__ and __getstate__
The text was updated successfully, but these errors were encountered:
Bug Description
Pickling
tagge_union
type is not working because__dataclass_fields__
is set on the object's__dict__
instead of the class__dict__
. Additionally,__dataclass_fields__
cannot be pickled automatically since it contains amappingproxy
.Expected Behavior
The
Option
type should be pickled successfully without errors.Code Example
Below is a minimal code example to illustrate the issue:
Additional Context
__dataclass_fields__
is set on the instance's__dict__
rather than the class's__dict__
.__dataclass_field__
contains amappingproxy
, which cannot be pickled automatically.Environment
Error Message
If applicable, include the error message you encountered:
Potential Solution
Implement
__setstate__
and__getstate__
The text was updated successfully, but these errors were encountered: