Opened 7 weeks ago

Last modified 6 weeks ago

#36507 assigned Cleanup/optimization

Document that only the base queryset’s prefetch_related() is preserved when using union()

Reported by: Clifford Gama Owned by: Clifford Gama
Component: Database layer (models, ORM) Version: 5.2
Severity: Normal Keywords: prefetch_related, union
Cc: Sniom Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Clifford Gama)

When using QuerySet.union() (possibly also intersection() and difference()) in Django, any prefetch_related() applied to the second (and third, etc) queryset is silently ignored. See forum thread in which it was suggested to open a documentation ticket. A docs improvement should also likely include the workaround for using Q objects to do all prefetches in the base qs (where possible), which is suggested by Simon in the forum.

Change History (4)

comment:1 by Clifford Gama, 7 weeks ago

Description: modified (diff)

comment:2 by Sniom, 7 weeks ago

Cc: Sniom added

comment:3 by Natalia Bidart, 7 weeks ago

Component: DocumentationDatabase layer (models, ORM)
Triage Stage: UnreviewedAccepted

Makes sense, thank you Clifford!

comment:4 by Clifford Gama, 6 weeks ago

Owner: set to Clifford Gama
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top