You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Assigning and restoring a State var's class default from several threads at once leaves a corrupted default #7511
Severity: LOW. Found on 0.10.0a2 and a3 (pre-release finding A3-04). It has not been independently verified.
Repro. 8 threads each assign and restore the same State var's class default 1500 times. On 0.10.0a3 (Python 3.11, 3.12 and 3.14), the var ends with:
_f == '7-426', a value from one of the threads;
default set to the dataclasses MISSING sentinel;
a stale default_factory lambda.
The expected end state is default == 'd' and no factory. On 0.10.0a2 the same stress also raised TypeErrors. On 0.9.12 the assignment simply replaced the class attribute, and the same stress ends correct.
Cause. The default/undo bookkeeping that #7461 / #7495 added to BaseStateMeta.__setattr__ / __delattr__ (reflex/state.py) is not guarded by a lock. Interleaved assign/restore pairs therefore push and pop each other's entries.
Impact. A realistic trigger is tests in threads patching class defaults at the same time (mock.patch.object, monkeypatch.setattr). Module-level assignments at import time are not affected. pytest-xdist uses processes, so it is not affected either.
Fix. Serialise the push/pop with a lock.
The A3-01 fix (undo entries must round-trip a rejected patch) touches the same code; one PR could cover both.
Repro: case thread_stress_assign_restore in a3_class_state/probes/adv7495.py. Output is in a3_class_state/logs/adv/adv7495.{a3,a2,s0912}.txt.
Closing as not planned. #7516 (merged as 064ba67) removed the class-default assign/restore bookkeeping that this race corrupted. BaseStateMeta.__setattr__ no longer keeps a default history. Assigning over a state var through its class now raises TypeError, so there is nothing left to lock.
Tests now patch the field instead, for example mock.patch.object(State.__fields__["x"], "default", v). That is a plain attribute set on the Field with no shared undo stack.
Activity
linear-code commentedon Oct 8, 2026
ENG-13213
prerelease 10-07 a3: follow-ups filed (#7506-#7511, enterprise#275, E…
a3 campaign: #7516 merged
masenf commentedon Oct 8, 2026
Closing as not planned. #7516 (merged as 064ba67) removed the class-default assign/restore bookkeeping that this race corrupted.
BaseStateMeta.__setattr__no longer keeps a default history. Assigning over a state var through its class now raisesTypeError, so there is nothing left to lock.Tests now patch the field instead, for example
mock.patch.object(State.__fields__["x"], "default", v). That is a plain attribute set on theFieldwith no shared undo stack.Generated by Claude Code
a3 campaign: close #7507 and #7511 as not planned