Another question: I've subclassed Query and overridden populate_existing() to always perform a flush() something like this:
def populate_existing(self): # This is extremely important since otherwise changes are lost for queried objects! self.session.flush() return super(CachingQuery, self).populate_existing() But when you said that sqla uses it as well, I realized I may be breaking something when I need the orm to "use query._get() to refresh an existing instance". However, when I search the sqlalchemy code for "populate_existing()", it seems you never invoke populate_existing() except in tests. Can I safely assume sqla will never invoke query.populate_existing()? If so, my mod is safe. If not, back to the drawing board... On Oct 25, 2:58 pm, Kent <jkentbo...@gmail.com> wrote: > I'm glad it's there... I need it when doing a refresh where I need to > keep the current objects (because I've written other things on the > object that the orm doesn't know about, so I need to keep the original > instance). > > Restating: it's there because its original intent was to deal with > expiration of attributes, whereas now, there are better ways to > accomplish expiration and so populate_existing()'s usefulness now is > only really the fact that it reuses existing objects. Does that sound > accurate? > > On 10/25/2011 2:39 PM, Michael Bayer wrote: > > > > > > > > > its used when we use query._get() to refresh an existing instance, and if i > > take it out some tests fail, so its accomplishing something. > > > that said, those operations which use it could certainly set autoflush > > distinctly, because if i were to use populate_existing() on in userspace > > (which I don't, the feature was added for 0.1 users before we knew how to > > expire things) I'd want it to autoflush first. But for now the change > > would be backwards incompatible with some hypothetical app that is using it > > and expects pending changes to be erased. > > > On Oct 25, 2011, at 2:18 PM, Kent wrote: > > >> Mike, > >> What is the rationale for making populate_existing() skip the > >> autoflush? > > >> Thanks, > >> Kent > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "sqlalchemy" group. > >> To post to this group, send email to sqlalchemy@googlegroups.com. > >> To unsubscribe from this group, send email to > >> sqlalchemy+unsubscr...@googlegroups.com. > >> For more options, visit this group > >> athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.