Operations on a list[T] | None var throw when the value is None

オープン 初心者向け
#7,826 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@masenf がすでに取り組んでいます。

2026年11月11日 から。

  • #7800 @masenf による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
frontend

調査の方向性

issue では ArrayVar とその配列操作が挙げられており、SetVar.to_array() における set のオプション処理が参考になります。変更 #7800 を読み、オプションのリストに対して contains と length がどのようにコンパイルされるかを追い、提示された例で失敗を再現してください。None が空のリストとしてレンダリングされ、その結果 contains が false、length が 0 となり、prerender が成功すれば完了です。

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

説明

Operations on a list[T] | None var that holds None throw on the frontend. #7800 fixes the same defect for set[T] | None (SetVar). Optional lists still have it.

Repro
import reflex as rx


class State(rx.State):
    items: rx.Field[list[str] | None] = rx.field(None)


def index():
    return rx.vstack(
        rx.text(State.items.contains("x")),
        rx.text(State.items.length()),
    )


app = rx.App()
app.add_page(index)
Result

The page does not render:

TypeError: Cannot read properties of null (reading 'includes')

length() fails the same way (null.length). The prod prerender fails for the same reason.

Expected

A None list acts as an empty list: contains is false and length is 0. This is the rule that #7800 uses for optional sets.

Suggested fix

Give an optional ArrayVar the same null-safe view that #7800 adds to SetVar.to_array(), which compiles to (x ?? []). Use that view in the array operations.

主要言語
Python
スター
29k
フォーク
1.8k
平均マージ
2日 22時間
マージ済み PR(30日)
143

環境構築

Codespaces で開く

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

はじめの一歩

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

reflex-dev/reflex のほかの issue

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

似ている issue

Python の issue をもっと見る

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

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