Prefetch with to_attr leaves the attribute missing when all forward relations are null
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
The repro in the issue shows a nullable FK prefetched with Prefetch(..., to_attr=...) raising AttributeError instead of setting the attribute to None when all keys are null. Start in tortoise/query_utils.py and the prefetch population code in fields/relational or the queryset prefetch path, where to_attr results are assigned. Look for the branch handling empty/null-only relation groups. Done means the repro returns None; a linked pull request (#2375) already exists, so check it before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Here Child.parent is a nullable foreign key to Parent. The same behavior occurs with nullable one-to-one fields. On current develop, prefetching the relation with to_attr leaves the requested attribute missing when every related key is null.
from tortoise.query_utils import Prefetch
child = await Child.create(parent=None)
row = await Child.filter(pk=child.pk).prefetch_related(
Prefetch("parent", Parent.all(), to_attr="cached_parent")
).get()
print(row.cached_parent)
The last line raises AttributeError. It should return None, consistent with prefetching a mixed group that includes a non-null relation.
- Lenguaje dominante
- Python
- Estrellas
- 5.6k
- Forks
- 540
- Merge medio
- 4 d 10 h
- PR fusionados (30 d)
- 31
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tortoise/tortoise-orm
-
URLValidator ignores an explicit empty scheme allowlistPosiblemente ocupada @IlyaKhalafi la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
tortoise/tortoise-orm#2393 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
tortoise/tortoise-orm#668 ·
Los mantenedores suelen responder en 2 días
-
in_transaction() leaks a pool connection when begin() is cancelledPosiblemente ocupada @inchang-ing la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
tortoise/tortoise-orm#2391 ·
Los mantenedores suelen responder en 2 días
-
Model.save() returns normally and writes nothing after the instance's INSERT was rolled backAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 40/100
tortoise/tortoise-orm#2383 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
Adding a custom Prefetch to a cloned queryset mutates the original queryPosiblemente ocupada @IlyaKhalafi la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
tortoise/tortoise-orm#2372 ·
Los mantenedores suelen responder en 2 días
Todos los issues de tortoise/tortoise-orm
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
521xueweihan/HelloGitHub#4237 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jejjohnson/gaussx#721 ·
Los mantenedores suelen responder en 1 día
-
mock-core-configs/etc/mock/rocky-10-riscv64.cfg contains the wrong architecture in config_opts['root']Posiblemente ocupada @jasonmontleon la tomó hace 4 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
rpm-software-management/mock#1834 ·
-
Switch to `container` resource detector in declarative configuration doc after 1.46.0 rebaseAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
elastic/elastic-otel-python#683 ·
Los mantenedores suelen responder en 1 día
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retriesAbiertofollow-up
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día