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

Renamed fields break dict(model) and default values_list

Aperta
#2,337 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.

  • #2339 di @IlyaKhalafi — aperta

Valutazione

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

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

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.