-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: properly initialize rx.Field annotated backend vars in mixin states #5909
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
fix: properly initialize rx.Field annotated backend vars in mixin states #5909
Conversation
CodSpeed Performance ReportMerging #5909 will create unknown performance changesComparing Summary
Footnotes
|
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.
Greptile Overview
Summary
Fixed backend variable initialization for mixin states when using rx.Field annotations by consolidating collection logic to properly unwrap Field objects.
- Previously, backend vars from mixins with
rx.Fieldwere processed in a separate loop that usedcopy.deepcopy(), which incorrectly stored the Field object itself instead of callingdefault_value()to extract the actual default value - Now backend vars from all mixins are collected upfront in the same comprehension that handles the main class, ensuring Field objects are properly unwrapped via
value.default_value() - Also fixes
is_backend_base_variable()to receivemixin_clsinstead ofcls, which correctly handles name-mangled private attributes specific to each mixin class - Removes 3 lines of redundant mixin backend var processing that was causing the bug
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The fix consolidates backend var initialization logic and eliminates a clear bug where Field objects were incorrectly deep-copied instead of unwrapped. The change follows the existing pattern used for the main class and aligns with how computed vars from mixins are already handled. No edge cases or breaking changes identified.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/state.py | 5/5 | Fixes proper initialization of rx.Field annotated backend vars in mixin states by collecting them upfront with correct Field unwrapping instead of deep copying them later |
Sequence Diagram
sequenceDiagram
participant C as Class.__init_subclass__
participant M as Mixin Classes
participant BV as Backend Vars Collection
participant F as Field Objects
C->>M: Get _mixins()
Note over C,M: Returns list of mixin classes
C->>BV: Collect backend vars from mixins + cls
loop For each mixin_cls in [*mixins, cls]
BV->>M: Get __dict__.items()
BV->>BV: Check is_backend_base_variable(name, mixin_cls)
alt Value is Field object
BV->>F: value.default_value()
F-->>BV: Return unwrapped default
else Value is not Field
BV->>BV: Use value directly
end
end
C->>BV: Update with annotated backend vars
loop For each mixin_cls in [*mixins, cls]
BV->>M: Get _get_type_hints().items()
BV->>BV: Check if not in new_backend_vars
BV->>C: cls._get_var_default(name, annotation)
C-->>BV: Return default value
end
C->>C: Merge inherited + new backend vars
Note over C: cls.backend_vars = {**inherited, **new}
1 file reviewed, no comments
Now I remember what "multiple issues" meant in #5629