Adding a custom Prefetch to a cloned queryset mutates the original query

Đang mở
#2,372 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@IlyaKhalafi đang làm issue này rồi.

Từ ngày 24/10/2026.

  • #2373 của @IlyaKhalafi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
5.6k
Fork
543
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
31

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tortoise/tortoise-orm

Tất cả issue của tortoise/tortoise-orm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.