-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
0.3.7 incorrectly pickles the class definition for module/class with the same name #634
Comments
FYI - possible fix for you to evaluate is the following. It appears to fix the issue on my end and I believe it passes tests. But I don't understand the rational for why it was done this way in the first place so it would be good for you to look at. If you'd rather have this as a PR, let me know and I'll do that.
|
Thanks for reporting, and the follow-up on this. I'll have a look... and yes, I'll make a PR if you don't. |
Slight modification:
With the above, I don't think there's a difference for Can you tell me what you think the behavior should be? |
I'm not at a computer where I can check this. But I assume "with the above" means my hack/fix. That could be true - I didn't test every combination. The fix I proposed may not be correct and/or complete. However that doesn't mean this isn't a bug and IMO it's a serious bug. The problem is that I have code that unpickles something and then says:
And the isinstance check will fail because dill made a clone of the class. So the unpickled object is no longer the same type as the object that was pickled. BTW regular pickle handles this case just fine - I don't know what it's doing but it correctly finds the package and unpickles to the original type. |
Currently, the expected behavior is that This enables |
Sorry - I didn't realize that was the desired behavior. I doubt it matters at this point but FYI in every use case we have (saving data, sending functions and data to parallel engines) it's really bad to make a copy of the class unless there is no other way to pickle it. I guess we'll try to figure out how to suppress that error and wrap the library to set byRef=True for all of our calls. |
No worries. Also, those are the most common |
This is a different bug than #628 and #604. When a class is defined in a file with the same name but imported into the package under that name (hiding the file name), then it's pickled with the full code block instead of just referencing the class name. Note that regular pickle has no problem with this case and performs correctly.
then run
and you will get (ID's will be different):
If I add
byref=True
to the dump call, then I get the correct class ID but also get a warning:I think the issue is in _dill.py in the _locate_function() which isn't finding the definition properly. I'm guess this is because it tries to do an import instead of looking in sys.modules. If that function checked sys.modules for the module name, it would find the module and then could call getattr() on that to see the class definition.
The text was updated successfully, but these errors were encountered: