On Feb 28, 2014, at 2:12 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote:

> 
> 
> On Friday, February 28, 2014 12:41:46 PM UTC-5, Michael Bayer wrote:
> 
> nope.   get() means, “the SELECT may not happen”.  eager loads are always 
> secondary to the fact that the row is being loaded.  if you want to 
> definitely load the row, say filter_by(id…).first().  
> 
> Poking at the source this may sort of do most of what you want if you say 
> query.populate_existing().get(1).  the components to make this operation 
> occur are there but they aren’t put together into a tested API (test coverage 
> and documentation are the main things that make it slow to add things like 
> this officially). 
> 
> Boo.
> 
> I have an "internal api" that handles most ( soon to be all ) the SqlAlchemy 
> management.  With the amount of code we have right now, it was the best way 
> to minimize and manage the impact of constantly evolving changes to the 
> schema or product requiresments.
> 
> There are times we want to use `filter()`, but for a handful of things -- 
> namely calculating Permissions/Authentication for ACLs -- we're switching to 
> use `get()`.  I only want to hit the DB once on these.  The queries are 
> dynamically generated; most don't have eagerloads.  some do.
> 
> .populate_existing will re-fetch the item, no matter what.   I don't want to 
> re-fetch the 'core' table if it is already loaded; I just want to fetch the 
> misc attributes if they haven't been loaded yet.
> 
> i'll just 'touch' the properties in my code if they're needed after the 
> 'get'.  that will load them.  


OK well it has to emit the SELECT for the primary row, but yes 
populate_existing will overwrite, so really, just any equivalent of 
query(User).filter_by(primary key).first() is really all you need here…we used 
to have a load() method that did this but it fell out of repair and nobody 
missed when i removed it, wasn’t worth maintaining.   The internal stuff used 
by get() in the “loading” module can probably be worked to provide this feature 
similarly to how get() works.


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to