fix(component): compare field values in BaseComponent.__eq__#6493
Conversation
bool() on a generator is always True, so any two same-class components compared equal. Use all() to actually evaluate the per-field comparisons.
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR fixes a genuine bug in
Confidence Score: 3/5Safe to merge only for components whose fields hold plain Python values; components with any Var-valued field will now raise VarTypeError on equality comparison instead of silently returning True. The fix correctly addresses the generator-truthiness bug and the new test demonstrates the intended behaviour. However, Var.eq returns a BooleanVar whose bool unconditionally raises VarTypeError, so any equality check involving a component that carries a reactive Var prop (ref, special_props, user-supplied state vars) will now throw at runtime. packages/reflex-base/src/reflex_base/components/component.py — the eq body needs a guard (e.g. identity fallback or isinstance(result, Var) check) before all() evaluates truthiness on field comparisons. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["BaseComponent.__eq__(self, value)"] --> B{"type(self) is type(value)?"}
B -- No --> C["return False"]
B -- Yes --> D["all(getattr(self,k) == getattr(value,k) for k in get_fields())"]
D --> E{"field value is plain Python type?"}
E -- Yes --> F["== returns bool, all() evaluates correctly"]
F --> G["return True or False"]
E -- No --> H["field value is Var, Var.__eq__ returns BooleanVar"]
H --> I["all() calls bool(BooleanVar)"]
I --> J["BooleanVar.__bool__ raises VarTypeError"]
Reviews (1): Last reviewed commit: "fix(component): compare field values in ..." | Re-trigger Greptile |
Var equality returns a BooleanVar and bool-ifying it raises VarTypeError, so the naive all(==) walk blew up on components with Var props or list/dict fields containing Vars. Compare Vars structurally via Var.equals and walk containers element-wise.
bool() on a generator is always True, so any two same-class components compared equal. Use all() to actually evaluate the per-field comparisons.
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features: