Nested data structures not connected to a State cause hard to decipher errors

Aperta
#6,589 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
frontend

Direzione di ricerca

Reproduce the behavior from the linked repository, then trace compiler.py at into_component through foreach.py and iter_tag.py, using the traceback as the entry point. Determine whether nested static BaseModel data should be supported or should produce a clearer error, and add coverage for both the working and failing nested references.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
When you directly pass a python data structure (nested BaseModel) to components you will sometimes get an exception that is hard to understand. It is made more difficult to figure out because accessing some nested elements of the data structure display fine while accessing others causes the exception.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
Either a clear exception explaining how data must be associated with State or allow static data structures to be used fully without exceptions. For example you have a catalog that won't change during the session so it doesn't need to be tracked via state.

Specifics (please complete the following information):

  • Python Version: 3.14
  • Reflex Version: 0.9.3
  • OS: Ubuntu 24.04.2 LTS

Traceback

  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/.venv/lib/python3.14/site-packages/reflex/compiler/compiler.py", line 816, in into_component
    component_called = component()
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/test_reflex_no_state_data/test_reflex_no_state_data.py", line 199, in index
    paint_color_scheme("40R", paint_scheme_catalogs["Approved Paint Schemes"]),
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/test_reflex_no_state_data/test_reflex_no_state_data.py", line 173, in paint_color_scheme
    rx.foreach(
    ~~~~~~~~~~^
        paint_scheme.elements,
        ^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        ),
        ^^
    )
    ^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/.venv/lib/python3.14/site-packages/reflex_components_core/core/foreach.py", line 115, in create
    component.children = [component._render().render_component()]
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/.venv/lib/python3.14/site-packages/reflex_base/components/tags/iter_tag.py", line 95, in render_component
    component = self.render_fn(arg)
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/test_reflex_no_state_data/test_reflex_no_state_data.py", line 175, in <lambda>
    lambda paint_scheme_element: paint_color_scheme_element(
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        paint_scheme_catalog, paint_scheme_element
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ),
    ^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/test_reflex_no_state_data/test_reflex_no_state_data.py", line 147, in paint_color_scheme_element
    rx.foreach(
    ~~~~~~~~~~^
        paint_scheme_element.paint_color_ids,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        ),
        ^^
    ),
    ^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/.venv/lib/python3.14/site-packages/reflex_components_core/core/foreach.py", line 115, in create
    component.children = [component._render().render_component()]
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/.venv/lib/python3.14/site-packages/reflex_base/components/tags/iter_tag.py", line 95, in render_component
    component = self.render_fn(arg)
  File "/Users/masenf/code/reflex-dev/test_reflex_no_state_data/test_reflex_no_state_data/test_reflex_no_state_data.py", line 150, in <lambda>
    paint_color=paint_scheme_catalog.paint_colors[paint_color_id],
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: Cannot access a primitive map with a Var. Consider calling rx.Var.create() on the map.
Happened while evaluating page 'index'
Lingua principale
Python
Stelle
29k
Fork
1.8k
Merge medio
3g 5h
PR unite (30g)
182

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di reflex-dev/reflex

Tutte le issue di reflex-dev/reflex

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.