-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Private dispatch table not checked #437
Comments
Btw one mitigation for this bug is to extend the CloudPickler instead, though if anyone knows how to fix this bug, that would be ideal.
|
Hi @wuisawesome, thanks for the report, The problem is known, and a PR has been submitted to solve the problem(#395), I'll try to review it soon. In the meantime, a possible workaround is explained in joblib/loky#260 and related issues. I don't have time to re-explain it here now, but it should look like: import cloudpickle
import io
import pickle
class CustomClass:
def __init__(self, *args):
self.x = len(args)
c = CustomClass()
def custom_reducer(obj):
return CustomClass, (0,)
io_buffer = io.BytesIO()
custom_pickler = cloudpickle.CloudPickler(io_buffer)
dt = pickle.Pickler.dispatch_table.__get__(custom_pickler)
new_dt = dt.new_child({CustomClass: custom_reducer})
pickle.Pickler.dispatch_table.__set__(custom_pickler, new_dt)
custom_pickler.dump(c)
io_buffer.seek(0)
c3 = cloudpickle.load(io_buffer)
assert c3.x == 1 # assertion fails becase c3.x == 0 |
Classifying this as an enhancement since IIRC we never claimed full compatibility with the |
I'm attempting to register a custom reducer with cloudpickle. In my use case, I need multiple
CloudPickler
's to serialize an object with different behavior, so I can't override the class-level global dispatch table.To demonstrate, assume I have the following class:
I can define a custom reducer and register it with a private dispatch table:
I can also prove that this doesn't affect the global dispatch table:
Unfortunately, when I try the same behavior with cloudpickle, it doesn't respect the private dispatch table:
(reference to how this was implemented in pickle)
The text was updated successfully, but these errors were encountered: