make return types picklable#99
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a quick one to help anyone using GrandCypher results downstream.
Fix pickling of query result keys (
AttributeRef,IDRef,EntityRef)Problem
The
strsubclasses ingrandcypher/types.pythat are used as result dictionary keys don't survive pickle round-trips. This breaks any downstream code that serialises GrandCypher query results — e.g. PySparkmap(),multiprocessing,joblib, or caching.AttributeRef— crashes on unpickle:AttributeRef.__new__takes two arguments (entity_name,attribute), but pickle's defaultstrreconstruction only passes the single string value:IDRef— silently corrupts on unpickle:IDRef.__new__wraps its argument asf"ID({entity_name})". Pickle reconstructs withstr(self)which is already"ID(a)", so__new__wraps it again:Root cause
Python's
strpickle path callscls.__new__(cls, str_value)on unpickle. This works when__new__takes exactly one argument matching the string value (as withEntityRef), but breaks when:__new__takes extra arguments (AttributeRef)__new__transforms the argument (IDRefprepends"ID(")Fix
Added
__getnewargs__to all three ref classes (AttributeRef,IDRef,EntityRef). This method tells pickle which arguments to pass to__new__during reconstruction, so the original constructor arguments are preserved across serialisation.Changes
grandcypher/types.py— added__getnewargs__toEntityRef,AttributeRef, andIDRefgrandcypher/test_types.py(new) — pickle round-trip tests for each ref class individually, plus an end-to-end test that pickles the full result dict from aGrandCypher.run()query