fix: Preserve object identity when pickling MutableProxy#6097
Merged
masenf merged 3 commits intoreflex-dev:mainfrom Jan 28, 2026
Merged
Conversation
Contributor
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)
|
masenf
approved these changes
Jan 28, 2026
benedikt-bartscher
added a commit
to benedikt-bartscher/reflex
that referenced
this pull request
Mar 12, 2026
…6097) * fix: Preserve object identity when pickling MutableProxy * thanks greptile, it wasn't a dataclass once
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.
No description provided.