Renamed fields break dict(model) and default values_list
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Run the reproduction script in the issue against a model with renamed columns to confirm both failures: dict(entry) raises AttributeError and the default values_list() returns []. The explicit values_list("id", "name") and values() paths already map field names correctly, so compare how they do it with the default paths. Done means both default paths use model field names, with dict(entry) giving id and name and the default tuple matching the explicit projection. Pull request #2339 is already open against this issue, so check it before starting.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Models with renamed columns fail in two default read paths. dict(model) raises AttributeError, and values_list() without arguments drops the renamed fields. If every stored field is renamed, the latter returns no rows even though a row exists.
Reproduced on develop at ac38923 with Python 3.14 and SQLite.
import json
from tortoise import Tortoise, fields, run_async
from tortoise.models import Model
class Entry(Model):
id = fields.IntField(primary_key=True, source_field="entry_id")
name = fields.TextField(source_field="entry_name")
async def run():
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
try:
await Tortoise.generate_schemas()
entry = await Entry.create(name="first")
result = {"values_list": await Entry.all().values_list(),
"explicit_values_list": await Entry.all().values_list("id", "name"),
"values": await Entry.all().values()}
try:
result["dict"] = dict(entry)
except AttributeError as error:
result["dict_error"] = str(error)
print(json.dumps(result))
finally:
await Tortoise.close_connections()
run_async(run())
The explicit projection returns [(1, "first")] and values() returns the expected dictionary. The default values_list() returns [], and converting the model to a dictionary tries to read an attribute named entry_id or entry_name.
Both default paths should use model field names, so the dictionary contains id and name, and the default tuple contains the same values as the explicit projection in declaration order.
- 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
-
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
-
Full refresh_from_db leaves source_field attributes staleForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 20/100
tortoise/tortoise-orm#2334 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di tortoise/tortoise-orm
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
aws-samples/sample-per-model-bedrock#261 ·
I maintainer di solito rispondono entro 1 giorno
-
[UI/Accessibility] Low contrast text visibility in country selection dropdown on settings pageAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
pwncollege/dojo#1188 ·
I maintainer di solito rispondono entro 1 giorno
-
bug launcher packaging
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
tenstorrent/tt-studio#1426 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python-attrs/cattrs#796 ·
I maintainer di solito rispondono entro 1 giorno