Reverse relation filters use attribute names for SQL columns
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with the reproduction script in the issue and print query.sql() to see which names reach the SQL. The bug is that the reverse-relation filter uses model attribute names (id, parent_id) where the table needs source_field column names (child_pk, parent_fk). Pull request #2338 is already open against this issue, so review or coordinate on it before starting new work. Done means the query returns the parent on SQLite and the one-to-one primary-key case in #2323 also works.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Reverse relation filters use model attribute names where SQL needs database column names. This affects the compared primary key and the join key when source_field is set.
Reproduced on develop at ac38923 with Python 3.14 and SQLite.
from tortoise import Tortoise, fields, run_async
from tortoise.models import Model
class Parent(Model):
name = fields.TextField()
class Child(Model):
id = fields.UUIDField(primary_key=True, source_field="child_pk")
parent = fields.ForeignKeyField(
"models.Parent", related_name="children", source_field="parent_fk"
)
async def run():
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
try:
await Tortoise.generate_schemas()
parent = await Parent.create(name="parent")
child = await Child.create(parent=parent)
query = Parent.filter(children__in=[child])
print(query.sql())
print(await query)
finally:
await Tortoise.close_connections()
run_async(run())
The query refers to child.id and child.parent_id, but the table has child_pk and parent_fk. It raises OperationalError instead of returning the parent.
The same primary-key mapping problem affects a reverse one-to-one relation whose primary key is the forward relation. It was reported in the review of #2323.
Related reports #1710 and #2029 were closed with workarounds. The failure still occurs on current develop. I also tested the current head of #2299, which addresses other one-to-one primary-key problems, and the reverse membership query still fails there.
- 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
-
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