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

オープン
#6,589 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
frontend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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'
主要言語
Python
スター
29k
フォーク
1.8k
平均マージ
3日 5時間
マージ済み PR(30日)
182

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

reflex-dev/reflex のほかの issue

reflex-dev/reflex の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。