Replace StateProxy with state locks held by the EventContext
Ā
MA
1mo ago+1046+1046+0123456789012345678901234567890123456789-923-923-012345678901234567890123456789
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
Part 2 of 4 of #7302. Stack: 1 field descriptors (#7312) ā 2 state locks ā 3 core state in reflex-base ā 4 dispatch_value. Based on #7312.
Description
Removes StateProxy, ReadOnlyStateProxy and ImmutableMutableProxy. Whether a state is writable is now decided at write time, in one place:
EventContexttracks the state trees whose locks it holds (StateLocks).EventContext.modify_statebinds the root to the context (_event_context), holds the lock for the whole event, and is the active context in its task while it holds it.- Every
Fieldwrite and everyMutableProxychange checks that the event context running in the current task holds the lock on the state's tree. If it doesn't, the write raisesImmutableStateError. Reads are always allowed. async with statetakes the lock again under the context the state was loaded in. It reloads the tree and puts this instance back into it, emits the delta on exit, and then hands the place back to the reloaded instance.- Background tasks,
rx.get_stateand callbacks get the plain state, read-only until entered withasync with. link_token_to_sidnow takes the lock through an event context. With the in-memory manager, the state it got was still bound to an earlier event, so recording the reconnecting session raisedImmutableStateError. A regression test covers this.
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
š¤ Generated with Claude Code
https://claude.ai/code/session_0145YmAVjKSJhdUFDcBP4FB9
Generated by Claude Code