#30874: Allow disabling of lazy loading of model and related fields on querysets
-------------------------------+--------------------------------------
Reporter: Rowan Seymour | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Simon Charette):
Shameless plug for [https://github.com/charettes/django-seal a third-party
library that implements just that].
The API is quite simple; it exposes a `seal()` method on `QuerySet` and
`Model` instances that turn all fetching attempts into warnings that can
be elevated to `UnsealedAttributeAccess(AttributeError)`. We've been using
it internally for a few projects so far and it does wonder to catch sneaky
queries and makes field deferring less of a foot gun.
Such an API will be necessary in a future `async` world where lazy
fetching cannot be awaited and thus must be prevented.
There's also a somewhat related approach to this problem in #28586 that
suggests to automatically prefetch ''to one'' fields.
[https://groups.google.com/forum/#!topic/django-developers/EplZGj-ejvg I
tend to agree with Anssi that this is a recipe for disaster]. In my
opinion it makes it impossible to determine what the ORM will do as your
project evolves and more relationships are added to your models, the same
kind of issues that calling `select_related()` without fields has.
Developer mailing list threads about both approaches
- https://groups.google.com/d/msg/django-
developers/AR6HwgSYV-M/bVmY9vs5EQAJ
- https://groups.google.com/d/msg/django-developers/EplZGj-
ejvg/nYb0jxSTBgAJ
--
Ticket URL: <https://code.djangoproject.com/ticket/30874#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.f1b95da3ba45be974ebe8cf586c56a92%40djangoproject.com.