-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix serialization/deserialization of weakrefs #61
Conversation
Oh man I waged epic battle with that ome-types/testing/test_model.py Lines 11 to 12 in 74103b1
The |
Even once we fix the ElementTree identity issue, there will still be an issue with the equality testing in |
I think any direct pickling of 1. On-demand XML serialization in 2. Change the I'm not sure how much real-world performance is actually on the table here. It depends on 1) How many XMLAnnotations are present in a given workload of images and how complex their XML is, and 2) How much pickling/unpickling is done. Maybe the clarity of the code is more important... (My assumptions are that pickling/unpickling would occur only once per image in typical use cases, like sending images to worker processes, and model equality testing will be very rare. I think poking around in the XMLAnnotation Element content will be rare too, but I'm less certain of that.) Sorry this has gotten pretty long. You guys let me know what you think, and if you can come up with any other solutions. |
This is awesome, thanks for all the sleuthing @jmuhlich! I guess I favor on-demand serialization in option number 1: putting the performance penalty (however small/large) on the pickling and equality checking. Feels like that's the less common operation, and the code would be a bit more sandboxed... You agree? I added benchmarking in #63 to help tell whether any of this really matters... |
updated this PR with overrides for thanks @JacksonMaxfield for raising this issue. this is definitely a useful thing to be testing. |
I just want to chime in and say this:
Is WILD. |
agreed... that's A) some nonsense going on there in etree and B) incredible detective work! |
I agree it's wild, and it never sat right with me... You encouraged me to create a minimum reproducible example and figure out exactly what's going on! Turns out the culprit isn't |
wow... |
I have convinced myself there is definitely a bug in that module namespace manipulation code in |
In my local working directory, I removed the new Now that we're down to it, I'm not sure resolving the weakrefs is the best way to handle pickling the References. I'm a little nervous about what happens when fragments of a model are pickled and not the top-level OME object. What about removing the |
That proposed change means people could still pickle a fragment of a model, but any refs will be broken on unpickle. I think this would prevent the kinds of misuse of pickled model objects that I'd expect. |
awesome. thanks for the PR to xmlschema. will be cool if that fixes other things too
I'm happy to try that out before we commit to the approach in this PR. will give it a go tomorrow. |
looks like your fix is already merged at xmlschema. I'm going to go ahead and merge this anyway so @JacksonMaxfield can at least use our master branch, and we can look at bumping our xmlschema requirement and cleaning it up in a later PR... perhaps before cutting a new release. |
forgot to add... I made the change you suggested in #61 (comment) (removing |
fixes #60 and pickling of OME objects with weakrefs by adding
__getstate__
and__setstate__
methods that de-reference re-reference the weakrefs.I added tests, and most of them are passing, but a handful of them with xml annotations are still failing with a very weird message:
furthermore, I don't get that error when I do the test manually in ipython. @jmuhlich, would love to hear if you have any thoughts on what might be happening there.