Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Full refresh_from_db leaves source_field attributes stale

Aperta
#2,334 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@IlyaKhalafi ci sta già lavorando.

Dal 15/10/2026.

  • #2335 di @IlyaKhalafi — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

Start with refresh_from_db() in the model code, where the default path iterates _meta.db_fields and uses column names as attribute names; the issue's snippet reproduces it with a source_field on a CharField. Pull request #2335 is already open against this issue, so review it before starting new work. Done means a full refresh updates attributes whose columns are renamed, and the fields=[...] path still works.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

refresh_from_db() leaves fields unchanged when their source_field differs from the model attribute name. This also affects foreign-key ID fields with renamed database columns.

To Reproduce

from tortoise import Model, fields

class Item(Model):
    id = fields.IntField(primary_key=True)
    title = fields.CharField(max_length=50, source_field="item_title")

# After initializing Tortoise and creating the schema
item = await Item.create(title="before")
await Item.filter(id=item.id).update(title="after")
await item.refresh_from_db()
assert item.title == "after"  # Still "before"

Passing fields=["title"] works. Omitting the argument, or passing an empty list or tuple, leaves the attribute stale.

Expected behavior

A full refresh should update model attributes from the current database row, including attributes with renamed columns.

Additional context

Reproduced on develop at ac3892300359c20934450ac949d0107269a61147. The default refresh iterates _meta.db_fields, which contains database column names, then uses those names as Python attributes. Models without renamed columns work.

Lingua principale
Python
Stelle
5.6k
Fork
523
Merge medio
2g 18h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tortoise/tortoise-orm

Tutte le issue di tortoise/tortoise-orm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.