I might go and make this.
I might go and make this.
The problem can be described as this: given an arbitrary point in a program, how can you infer what data is required at a future point without executing code between those two points?
I’d love to see you go make a solution to this.
You’d have exactly the same issue as you’d have if you’d call “get_author_publications” O(n) times in some nested call stack. Except getting out of it wouldn’t be as easy as calling “select_related(…)” - you’d instead just end up re-inventing an ORM.
This could be where we differ. I wouldn't propose that at all, I'd propose writing a query more appropriate for whatever part of the code contains the iteration.
This is an identical solution to adding “select_related()” in the right places, and thus we loop back to the start of our thread.
It's not an illusion, it's an abstraction that sometimes leaks. But all abstractions are leaky.
There are plenty of projects that never reached a point where N+1 became something they needed to worry about. There are plenty of projects where ORM allowed to delay the need to worry about N+1, thus allowing them focus on product.
And that means that abstraction is working fine. It's not perfect, but it's working.