News for hackers. Stuff that matters.
Re:12 requests per second: A realistic look at Python web fr... by lacksconfidence on Friday February 19, 2021 @07:28AM (#26192397)
Perhaps i'm a bit odd, but when I'm going to lean on an ORM to do things I expect it to actually do them. I expect that foo.user_id does not exist, because that representation has been transformed into an object. foo.user.id should be the only viable reference to the id. foo.user.id should return the value it already knows, any other property access i would expect will do the equiv of `select * from ...` if the object has not previously been populated.

Now perhaps some ORM's prefer to be thinner, to provide more footguns via a leaky abstraction that mixes implementation details with the object mapping. I don't think those are good implementaations.

Re:12 requests per second: A realistic look at Python web fr... by RussianCow on Friday February 19, 2021 @04:27PM (#26198244)
> Now perhaps some ORM's prefer to be thinner, to provide more footguns via a leaky abstraction that mixes implementation details with the object mapping. I don't think those are good implementaations.

To me, it seems like the (hypothetical?) implementation you're talking about is much more leaky and footgun-y than the more straightforward ("thinner", in your words) version. In order for foo.user.id to not execute a new query, foo.user would have to return some sort of proxy object that only fetched the user row when you tried to access a field that hasn't been loaded. That's way more magic than the more obvious solution—which is to load the row when you access the related object—and could easily cause more problems than it solves in the long run when you need to debug very specific queries.

Furthermore, how is going out of your way to hide a field that exists in the database (user_id) not the definition of a leaky abstraction? What purpose does it serve to direct you through an unnecessary layer if all you need is the ID?

Re:12 requests per second: A realistic look at Python web fr... by rglullis on Friday February 19, 2021 @11:07AM (#26194561)
> I expect that foo.user_id does not exist, because that representation has been transformed into an object.

Or you can just consider user_id to be a reference pointer that is part of foo, while user.id is an attribute of user. Totally different things and I am glad that the distinction is there.

Re:12 requests per second: A realistic look at Python web fr... by bottled_poe on Friday February 19, 2021 @07:48AM (#26192554)
I’m sure there are valid engineering reasons to do it this way. One that comes to mind is memory footprint in allocating the objects associate with foreign key references.
Re:12 requests per second: A realistic look at Python web fr... by jtdev on Friday February 19, 2021 @08:45AM (#26193041)
Wow! Who would have thought that using an ORM would create so much uncertainty in a codebase.