tortoise / tortoise/tortoise-orm
Nested Prefetch with queryset and to_attr gets ignored
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
Nested Prefetch does not work
To Reproduce
await AModel.filter().prefetch_related(
Prefetch("models",
queryset=BModel.filter().prefetch_related(
Prefetch("cmodels",
queryset=CModels.filter(), to_attr=has_cmodels
)
)
)
Expected behavior
the result contains the field has_cmodels
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the nested prefetch_related and Prefetch reproducer in the issue, focusing on the inner queryset and its to_attr value. Trace how nested prefetching handles the cmodels relation and verify whether the resulting objects expose has_cmodels. Done means the reproducer returns the expected field without breaking other prefetch behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100