fix: properly initialize rx.Field annotated backend vars in mixin states#5909
Merged
masenf merged 4 commits intoreflex-dev:mainfrom Oct 22, 2025
Conversation
CodSpeed Performance ReportMerging #5909 will create unknown performance changesComparing Summary
Footnotes
|
Contributor
There was a problem hiding this comment.
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
masenf
approved these changes
Oct 22, 2025
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.
Now I remember what "multiple issues" meant in #5629