Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`get_field_type` and `get_attribute_access_type` read `__fields__` and emit `PydanticDeprecatedSince20` on each field access

未关闭 适合新手
#7,561 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

已弃用的读取位于 reflex_base/utils/types.py:get_field_type 中第 589-594 行以及 get_attribute_access_type 中第 710 行的 __fields__ 访问。首先运行 issue 中的复现脚本,并检查警告数量。当脚本报告 0 条 PydanticDeprecatedSince20 警告,且字段类型的解析结果与之前一致时,即完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug
Reflex reads cls.__fields__ when it resolves the type of a field on a Pydantic v2 model. Pydantic v2 deprecates __fields__, so each read emits PydanticDeprecatedSince20. One field access on a Var emits 7 warnings.

The reads are in reflex_base/utils/types.py (reflex-base 0.9.12):

  • get_attribute_access_type, line 710: 2 reads.
  • get_field_type, lines 589 to 594: 5 reads.

The same code is in 0.9.13 and 0.10.0. In 0.10.0, the lines are 580 to 585 and 701.

To Reproduce

import warnings

import pydantic
import reflex as rx


class Item(pydantic.BaseModel):
    name: str
    size: int


class ItemState(rx.State):
    items: list[Item] = []


with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    rx.foreach(ItemState.items, lambda item: rx.text(item.name, " ", item.size))

deprecations = [record for record in caught if issubclass(record.category, pydantic.warnings.PydanticDeprecatedSince20)]
print(f"{len(deprecations)} PydanticDeprecatedSince20 warnings")
for warning in deprecations:
    print(f"  {warning.filename.split('site-packages/')[-1]}:{warning.lineno}")

Output with Python 3.14.6, reflex 0.9.12, reflex-base 0.9.12 and pydantic 2.14.0:

14 PydanticDeprecatedSince20 warnings
  reflex_base/utils/types.py:710
  reflex_base/utils/types.py:710
  reflex_base/utils/types.py:589
  reflex_base/utils/types.py:590
  reflex_base/utils/types.py:591
  reflex_base/utils/types.py:592
  reflex_base/utils/types.py:594
  (the same 7 lines again for the second field)

The script accesses 2 fields, and each access emits 7 warnings. In our app, one page compile does 176 field accesses and emits 1,232 warnings.

Expected behavior
Reflex resolves field types on Pydantic v2 models without deprecation warnings.

Specifics (please complete the following information):

  • Python Version: 3.14.6
  • Reflex Version: 0.9.12
  • OS: macOS 26.6.2 (build 25G83), on Apple Silicon (arm64)

Additional context
Related: #6241, #6135.

主要语言
Python
星标
28.9k
派生
1.8k
平均合并
2 天 14 小时
30 天内合并 PR
211

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

reflex-dev/reflex 的其他 Issue

查看 reflex-dev/reflex 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。