I do this often. All you need to do it stash the object into something that is in the scope you wish the object to survive. An array or dict works perfectly:
stashed = [] def f(s): ... parents = s.query(Parent).all() # load all parents objects in identity map stashed.append(parents) In the case of web programming, I stash loaded objects onto the `request` object. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.