Comparing an item-access var (e.g. state.dict["k"] >= 90) raises ObjectItemOperation error in 0.9.x
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 58/100
Rechercherichtung
Start with the minimal reproduction using State.metrics["current"] �>= 90 inside rx.cond, then trace how item access is evaluated when a var is used as a boolean during reflex run. Done means the comparison resolves to False for the shown values and renders "Below threshold" without raising ObjectItemOperation.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 29k
- Forks
- 1.8k
- Ø Merge
- 3 T. 5 Std.
- Gemergte PRs (30 T.)
- 182
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus reflex-dev/reflex
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
reflex-dev/reflex#8026 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Kept env.py failure: the "move it aside" hint is dropped and a full traceback is logged when alembic.ini uses a relative script_locationEvtl. vergeben @MaiAditya hat das vor 13 Tagen übernommen. Offenbug release-train
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
reflex-dev/reflex#7856 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
0.9.12 changelog follow-ups: the #7132 "_get_was_touched" entry describes unreachable behaviour, #7115's hasattr/getattr change is undocumented, #7131's wordingEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenrelease-train
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
reflex-dev/reflex#7260 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
ClientStateVar: a component that mounts while the value is non-default never re-renders on the push back to the defaultEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
reflex-dev/reflex#6823 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
documentation upstream
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
reflex-dev/reflex#6436 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in reflex-dev/reflex
Ähnliche Issues
-
todo
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
tonybaloney/CSnakes#864 ·
-
infra
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
libre-embedded/svgen#72 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Genesis-Embodied-AI/genesis-world#3950 ·
Maintainer antworten meist innerhalb von 1 Tag
-
accessibility
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag