-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: Preserve object identity when pickling MutableProxy #6097
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
base: main
Are you sure you want to change the base?
fix: Preserve object identity when pickling MutableProxy #6097
Conversation
Greptile OverviewGreptile SummaryThis PR fixes a bug where The fix affects state serialization when using Redis state manager, ensuring that when the same object is referenced multiple times (e.g., Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application
participant SM as StateManager
participant Pickle as pickle.dumps
participant MP as MutableProxy
participant WO as Wrapped Object
participant Memo as Pickle Memo
Note over App,Memo: Before: Object identity lost
App->>SM: Store state with MutableProxy
SM->>Pickle: pickle.dumps(data)
Pickle->>MP: __reduce_ex__(protocol)
MP->>WO: delegate to __reduce_ex__
WO-->>Pickle: (class, args, state)
Note over Memo: New memo entry for wrapped object
Pickle->>Memo: Store object reference
Note over Memo: Memo doesn't recognize proxy wraps same object
Pickle-->>SM: Serialized bytes (identity lost)
Note over App,Memo: After: Object identity preserved
App->>SM: Store state with MutableProxy
SM->>Pickle: pickle.dumps(data)
Pickle->>MP: __reduce_ex__(protocol)
MP-->>Pickle: (_unwrap_for_pickle, (wrapped_obj,))
Note over Memo: Memo sees actual wrapped object
Pickle->>Memo: Check if wrapped_obj already in memo
alt Object already in memo
Memo-->>Pickle: Return existing reference
else New object
Memo->>Pickle: Store new reference
end
Pickle-->>SM: Serialized bytes (identity preserved)
Note over App,Memo: Deserialization
SM->>Pickle: pickle.loads(bytes)
Pickle->>Memo: Reconstruct objects using memo
Note over Memo: Same object referenced multiple times
Pickle-->>SM: Reconstructed data (same object identity)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
No description provided.