W dniu środa, 16 sierpnia 2017 14:48:54 UTC+2 użytkownik Luke Plant napisał: > > I completely agree that visibility of this problem is a major issue, and > would really welcome work on improving this, especially in DEBUG mode. One > option might be a method that replaces lazy loads with exceptions. This > would force you to add the required `prefetch_related` or `select_related` > calls. You could have: > > .lazy_load(None) # exception on accessing any non-loaded FK objects > > .lazy_load('my_fk1', 'my_fk2') # exceptions on accessing any unloaded FK > objects apart from the named ones > > .lazy_load('__any__') # cancel the above, restore default behaviour > > This (or something like it) would be a different way to tackle the problem > - just throwing it out. You could have a Meta option to do > `.lazy_load(None)` by default for a Model. I've no idea how practical it > would be to wire this all up so that is works correctly, and with nested > objects etc. >
Would love if Django could be told to require explicit data fetches. This and replacing QuerySet.__iter__ with an explicit fetch() (and lazy_fetch()) would make it much easier to reason about large codebases. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to firstname.lastname@example.org. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1fa90611-66cc-4d06-992c-55164913679d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.