Full refresh_from_db leaves source_field attributes stale
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 20/100
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tortoise/tortoise-orm
-
pydantic_model_creator returns a cached class that ignores model_config, validators and moduleForse già presa @moneebullah25 l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
tortoise/tortoise-orm#2310 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
tortoise/tortoise-orm#668 ·
I maintainer di solito rispondono entro 2 giorni
-
refresh_from_db silently ignores fields supplied as an iteratorForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
tortoise/tortoise-orm#2341 ·
I maintainer di solito rispondono entro 2 giorni
-
Renamed fields break dict(model) and default values_listForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
tortoise/tortoise-orm#2337 ·
I maintainer di solito rispondono entro 2 giorni
-
Reverse relation filters use attribute names for SQL columnsForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
tortoise/tortoise-orm#2336 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di tortoise/tortoise-orm
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
cellrishi-code/claude-skills-atlas#165 ·
I maintainer di solito rispondono entro 1 giorno
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-webui/open-webui#32635 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Filters: ?field:ne=null matches NULL rows instead of non-NULL onesForse già presa @rshdhere l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Netflix/metaflow-service#504 ·
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
gke-labs/kube-agents#3394 ·
I maintainer di solito rispondono entro 1 giorno
-
A2A audit timestamps end in +00:00Z (invalid ISO 8601)Forse già presa @O1sumitkumar l’ha presa oggi. Apertabug good first issue help wanted python
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno