Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

refresh_from_db silently ignores fields supplied as an iterator

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

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

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

2026年10月15日 から。

  • #2342 @IlyaKhalafi による — オープン

評価

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

調査の方向性

The bug is in Model.refresh_from_db(fields=...), where the iterable is consumed by .only(*fields) before the refreshed values are copied back, so an iterator behaves differently from a list. Start by reading refresh_from_db and the .only() call it makes, then run the reproduction script in the issue against SQLite to confirm before 1 is printed. Done means an iterator of field names refreshes the same fields as the equivalent list, and an empty iterator behaves like an empty list. Pull request #2342 already targets this, so check it before starting.

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

説明

Model.refresh_from_db(fields=...) accepts Iterable[str], but a generator is consumed by .only(*fields) before the refreshed values are copied back. The query succeeds while the model instance keeps its stale values.

Reproduced on develop at ef637d4 with SQLite and Python 3.14.

from tortoise import Tortoise, fields, run_async
from tortoise.models import Model

class Counter(Model):
    name = fields.CharField(max_length=30)
    count = fields.IntField(default=1)

async def main():
    await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
    try:
        await Tortoise.generate_schemas()
        obj = await Counter.create(name="before", count=1)
        await Counter.filter(pk=obj.pk).update(name="after", count=2)
        await obj.refresh_from_db(fields=iter(["name"]))
        print(obj.name, obj.count)
    finally:
        await Tortoise.close_connections()

run_async(main())

This prints before 1. Passing ["name"] prints the expected after 1.

An empty field iterator also raises ValueError from .only(), while an empty list refreshes all fields. Field iterators should behave like the equivalent lists and preserve selective refresh.

This differs from #2335, which fixes model attribute names when columns are renamed.

主要言語
Python
スター
5.6k
フォーク
523
平均マージ
2日 18時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

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

tortoise/tortoise-orm のほかの issue

tortoise/tortoise-orm の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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