Adding a custom Prefetch to a cloned queryset mutates the original query
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
The repro imports Prefetch from tortoise.query_utils and calls prefetch_related. Read the prefetch_related implementation and the queryset clone logic. Run the snippet to confirm second_parent leaks into original. Done when original queryset remains unchanged; PR #2373 is open.
Written by the indexing model from the issue text.
Description
Here Child.parent is a foreign key to Parent. On current develop, a queryset clone shares the lists of custom prefetch queries with the original. Adding another Prefetch for the same relation changes both queries.
from tortoise.query_utils import Prefetch
original = Child.all().prefetch_related(
Prefetch("parent", Parent.all(), to_attr="first_parent")
)
derived = original.prefetch_related(
Prefetch("parent", Parent.all(), to_attr="second_parent")
)
row = await original.first()
When a child exists, row also has second_parent even though it was only requested on derived. The original queryset should remain unchanged.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 540
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 31
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from tortoise/tortoise-orm
-
URLValidator ignores an explicit empty scheme allowlistPossibly taken @IlyaKhalafi claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
tortoise/tortoise-orm#2393 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tortoise/tortoise-orm#668 ·
Maintainers usually reply within 2 days
-
in_transaction() leaks a pool connection when begin() is cancelledPossibly taken @inchang-ing claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
tortoise/tortoise-orm#2391 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 40/100
tortoise/tortoise-orm#2383 · 2 comments ·
Maintainers usually reply within 2 days
-
Prefetch with to_attr leaves the attribute missing when all forward relations are nullPossibly taken @IlyaKhalafi claimed this 10 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
tortoise/tortoise-orm#2374 ·
Maintainers usually reply within 2 days
All issues in tortoise/tortoise-orm
Similar issues
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retriesOpenfollow-up
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Built-in QUBO fallback applies bitwise xor to floating binary statesPossibly taken @iloveeyjafjalla claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
qboson/kaiwu-pytorch-plugin#1702 ·
Maintainers usually reply within 3 days
-
bug v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/python-sdk#3811 ·
Maintainers usually reply within 1 day
-
cost:cheap practicality:seen-in-the-wild severity:medium
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
Maintainers usually reply within 1 day