Changes between Initial Version and Version 6 of Ticket #37300


Ignore:
Timestamp:
Aug 31, 2026, 12:14:09 PM (2 weeks ago)
Author:
Jacob Walls
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37300

    • Property Component UncategorizedDatabase layer (models, ORM)
    • Property Severity NormalRelease blocker
    • Property Type UncategorizedBug
    • Property Owner set to Yassin Bahri
    • Property Status newassigned
    • Property Has patch set
    • Property Triage Stage UnreviewedAccepted
  • Ticket #37300 – Description

    initial v6  
    11In Django ≤ 6.0, when a Prefetch with a custom queryset (with no explicit .using()) was used to prefetch a forward ForeignKey or OneToOneField, get_prefetch_querysets() called queryset._add_hints(instance=instances[0]), so the default router's db_for_read() resolved to the parent instances' database via the instance hint. The custom prefetch queryset therefore ran against the same database as the outer queryset.
    22
    3 In 6.1, commit 821619aa876158e8d6dcedebd0dbc2e0e0b41295 (Refs #28586, "Simplified related descriptor get_queryset() methods") moved the hint into get_queryset(instance=...), which is only called when no custom queryset is passed. The custom-queryset path in ForwardManyToOneDescriptor.get_prefetch_querysets() and ReverseOneToOneDescriptor.get_prefetch_querysets() lost the _add_hints() call entirely, so a custom prefetch queryset now silently runs against "default" even when the outer queryset uses another alias. The reverse many-to-one and many-to-many manager paths still call _add_hints() for custom querysets, so those relation types are unaffected — making the forward FK/O2O behavior inconsistent with them as well as with 6.0.
     3In 6.1, commit 821619aa8771ef211c4c4922001efdf914201ca3 (Refs #28586, "Simplified related descriptor get_queryset() methods") moved the hint into get_queryset(instance=...), which is only called when no custom queryset is passed. The custom-queryset path in ForwardManyToOneDescriptor.get_prefetch_querysets() and ReverseOneToOneDescriptor.get_prefetch_querysets() lost the _add_hints() call entirely, so a custom prefetch queryset now silently runs against "default" even when the outer queryset uses another alias. The reverse many-to-one and many-to-many manager paths still call _add_hints() for custom querysets, so those relation types are unaffected — making the forward FK/O2O behavior inconsistent with them as well as with 6.0.
    44
    55Reproduction, with a "replica" alias configured identically to "default":
Back to Top