Repository navigation
Commit 064ba67
Back out class-level default assignment; refuse to assign over a state var (#7516)
* Back out class-level default assignment; refuse to assign over a state var
#7461 made assigning a declared var through its state class update the
var's default, and #7495 added patch/restore history and kept browser
storage on plain assignments. That layer on top of the Field descriptor
brought more edge cases than this release should carry, so it comes out.
BaseStateMeta.__setattr__ now raises TypeError when the name resolves to
a state var's field, instead of either replacing the descriptor (which
broke the var, as on 0.10.0a1) or updating its default. Assigning the
var's own field back is a no-op, so a patch whose assignment failed
cleans up quietly; deleting the attribute first still replaces the var
on purpose. ClassVars and new names stay assignable, and add_var's new
fields bind through the guard because add_var rejects existing names.
Defaults are configured on the field instead:
State.__fields__["x"].default = value, or default_factory. Tests patch
the field rather than the class attribute. The ComponentState docs go
back to the __fields__ pattern, now with a note on per-component browser
storage keys.
Kept from #7461: the saved-state schema without defaults (and its legacy
fallback), reset() using default_value(), declared storage factories in
compile_client_storage, and the TypeVar/Protocol handling in _isinstance.
Kept from #7495: the dev-mode guard against undeclared mangled names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Make the class-default docs examples self-contained
The base vars example set a factory on a field TickerState does not have,
and the ComponentState storage example used get_component arguments that
were never declared. Both now declare what they use.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Format the ComponentState storage example
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Name the var when a patch through a substate is refused
mock.patch.object on a var a substate inherits was refused by the guard,
but its cleanup then deleted the attribute it never set on the substate,
and the resulting AttributeError hid the TypeError. Deleting an inherited
var through a class now raises the same TypeError, built by one helper.
The base vars docs now say what a plain string default does to a browser
storage var: a str-annotated var becomes an ordinary var, a storage-typed
one stays in storage under the default key and options.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Mention factory-backed storage defaults in the base vars docs
A var annotated with a storage type also keeps its storage name and
options when its default_factory returns a storage value, which the
compiler reads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Show only working code in the class-default docs examples
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Note that each backend worker holds its own ClassVar value
A ClassVar set at import time starts the same in every worker, but a
lock only serializes its own worker's sessions and a change made after
the workers start stays in that worker.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
* Point cross-session runtime values to SharedState, not a state var
A regular state var is per session, so it cannot carry a value every
session sees; a linked rx.SharedState or an external store can.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjCrbdguMkfe4bhbaREiwo
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9b81d8c commit 064ba67
21 files changed
Lines changed: 303 additions & 1353 deletions
File tree
- docs
- app/news
- changelog/upgrading
- state_structure
- vars
- news
- packages/reflex-base
- news
- src/reflex_base/vars
- reflex
- istate
- tests
- integration
- tests_playwright
- units
- compiler
- components
- reflex_base/vars
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
56 | 73 | | |
57 | 74 | | |
58 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
167 | 186 | | |
168 | 187 | | |
169 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
123 | 119 | | |
124 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
125 | 131 | | |
126 | | - | |
| 132 | + | |
127 | 133 | | |
128 | | - | |
129 | | - | |
130 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
| |||
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
167 | | - | |
| 173 | + | |
| 174 | + | |
168 | 175 | | |
169 | | - | |
| 176 | + | |
170 | 177 | | |
171 | 178 | | |
172 | 179 | | |
| |||
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
| 193 | + | |
| 194 | + | |
186 | 195 | | |
187 | 196 | | |
188 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
This file was deleted.
This file was deleted.
This file was deleted.
0 commit comments