Describe the bug
In Reflex 0.9.x, comparing a var that originated from a dictionary or list item-access against a Python literal raises an ObjectItemOperation error at render time. The same expression worked in 0.8.x.
The bug surfaces specifically inside rx.cond and other places where a var needs to be evaluated as a boolean.
To Reproduce
import reflex as rx
class State(rx.State):
metrics: dict[str, int] = {"current": 75, "limit": 100}
def index() -> rx.Component:
return rx.cond(
State.metrics["current"] >= 90,
rx.text("Above threshold"),
rx.text("Below threshold"),
)
app = rx.App()
app.add_page(index)
Running reflex run raises:
TypeError: '>=' not supported between instances of 'ObjectItemOperation' and 'int'
Expected behavior
The comparison should evaluate against the resolved value, returning False in this case (75 < 90), and render the second branch.
Workaround
Compute the comparison in the state and expose a derived var:
class State(rx.State):
metrics: dict[str, int] = {"current": 75, "limit": 100}
@rx.var
def is_above_threshold(self) -> bool:
return self.metrics["current"] >= 90
This works but is awkward for ad-hoc per-render checks.
Specifications
- Reflex version: 0.9.3
- Python version: 3.12
- OS: macOS
Additional context
Possibly related to closed issues #4380 (ObjectVar __getitem__ typing issues), #5849 (make indexing more null friendly), and #4647 (recursive datatypes checking) but the comparison failure mode persists in 0.9.3.
Describe the bug
In Reflex 0.9.x, comparing a var that originated from a dictionary or list item-access against a Python literal raises an
ObjectItemOperationerror at render time. The same expression worked in 0.8.x.The bug surfaces specifically inside
rx.condand other places where a var needs to be evaluated as a boolean.To Reproduce
Running
reflex runraises:Expected behavior
The comparison should evaluate against the resolved value, returning
Falsein this case (75 < 90), and render the second branch.Workaround
Compute the comparison in the state and expose a derived var:
This works but is awkward for ad-hoc per-render checks.
Specifications
Additional context
Possibly related to closed issues #4380 (ObjectVar
__getitem__typing issues), #5849 (make indexing more null friendly), and #4647 (recursive datatypes checking) but the comparison failure mode persists in 0.9.3.