Prefetch with to_attr leaves the attribute missing when all forward relations are null
メンテナーはふだん 2 日以内に返信
評価
調査の方向性
The repro in the issue shows a nullable FK prefetched with Prefetch(..., to_attr=...) raising AttributeError instead of setting the attribute to None when all keys are null. Start in tortoise/query_utils.py and the prefetch population code in fields/relational or the queryset prefetch path, where to_attr results are assigned. Look for the branch handling empty/null-only relation groups. Done means the repro returns None; a linked pull request (#2375) already exists, so check it before starting.
索引モデルが issue の本文から書いたものです。
説明
Here Child.parent is a nullable foreign key to Parent. The same behavior occurs with nullable one-to-one fields. On current develop, prefetching the relation with to_attr leaves the requested attribute missing when every related key is null.
from tortoise.query_utils import Prefetch
child = await Child.create(parent=None)
row = await Child.filter(pk=child.pk).prefetch_related(
Prefetch("parent", Parent.all(), to_attr="cached_parent")
).get()
print(row.cached_parent)
The last line raises AttributeError. It should return None, consistent with prefetching a mixed group that includes a non-null relation.
- 主要言語
- Python
- スター
- 5.6k
- フォーク
- 540
- 平均マージ
- 4日 10時間
- マージ済み PR(30日)
- 31
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tortoise/tortoise-orm のほかの issue
-
URLValidator ignores an explicit empty scheme allowlist対応中かも @IlyaKhalafi が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
tortoise/tortoise-orm#2393 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
tortoise/tortoise-orm#668 ·
メンテナーはふだん 2 日以内に返信
-
in_transaction() leaks a pool connection when begin() is cancelled対応中かも @inchang-ing が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
tortoise/tortoise-orm#2391 ·
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 40/100
tortoise/tortoise-orm#2383 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
Adding a custom Prefetch to a cloned queryset mutates the original query対応中かも @IlyaKhalafi が 10 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
tortoise/tortoise-orm#2372 ·
メンテナーはふだん 2 日以内に返信
tortoise/tortoise-orm の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
521xueweihan/HelloGitHub#4237 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jejjohnson/gaussx#721 ·
メンテナーはふだん 1 日以内に返信
-
mock-core-configs/etc/mock/rocky-10-riscv64.cfg contains the wrong architecture in config_opts['root']対応中かも @jasonmontleon が 4 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
rpm-software-management/mock#1834 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
elastic/elastic-otel-python#683 ·
メンテナーはふだん 1 日以内に返信
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retriesオープンfollow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信