Auto-prefetching with model field fetch modes in Django 6.1
summary
Django 6.1 adds concrete fetch modes that automatically prefetch single-valued relations without listing fields, shipping fetch_peers (just-in-time prefetch), raise mode (error on unexpected access) and the default fetch_one. It demonstrates configuring modes on model managers, shows how to write a custom mode that logs a warning instead of raising, and explains tradeoffs: lazy prefetching increases the race window, does not cover multivalued relations, and can amplify existing overfetching if applied indiscriminately.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 0:24About the speaker
- 1:27What fetch modes solve
- 4:36Traditional N+1 solutions
- 6:24Fetch peers vs select related
- 8:08Fetch modes in Django 6.1
- 11:42History of fetch modes
- 12:45Single valued relationships
- 13:48Pitfalls with fetch peers
- 15:56Lazy fetching implications
- 17:40Reducing boilerplate with managers
- 18:42Raise mode for debugging
- 19:06Creating custom fetch modes
- 20:11Q&A begins
