birkenfeld / serde-pickle

Rust (de)serialization for the Python pickle format.
Apache License 2.0
185 stars 27 forks source link

Skip unresolvable elements #13

Closed andreasKroepelin closed 3 years ago

andreasKroepelin commented 3 years ago

I experience the following situation: In python, there is some object foo which I serialize using pickle and try to deserialize in Rust using serde-pickle, where it fails with an UnresolvedGlobal error. However, serializing and deserializing foo.x actually works and I'm in fact only interested in foo.x.

So my question is: Is there a way to just skip whatever is unresolvable and return everything that could be resolved?

Unfortunately, I could not find out what actually causes the problem with foo, yet.

birkenfeld commented 3 years ago

Hm, I understand and think that this is a valid use case. For the next version (1.0) I will add a way to pass an Options struct to the deserializing methods, and such a mode could be added there.

To find out more about the global, call python -m pickletools <your file> which disassembles all the pickle opcodes. Globals are marked with GLOBAL or STACK_GLOBAL, the name of the global should be either directly there or pushed on the stack before it.

birkenfeld commented 3 years ago

BTW, what data type are you deserializing into? serde_pickle::Value?

andreasKroepelin commented 3 years ago

That's great to hear, looking forward to that development! Thanks for pointing out pickletools, I'll give that a try. And yes, I deserialize into serde_pickle::Value.

birkenfeld commented 3 years ago

Ok, the option is now implemented; if you are still interested it would be nice if you could test out master before I release 1.0.

andreasKroepelin commented 3 years ago

Very cool, thanks! Unfortunately, I'm not working on that project anymore and currently don't have time to test it out. I might do so at some time, though!