perhaps I'm missing something but wouldn't you just change the update() here to all(), so that you SELECT only those rows you care about into memory, then change each "foo" as needed and flush? I'm not seeing what the issue is. The row isn't locked if you aren't using SELECT..FOR UPDATE.
On Apr 23, 2014, at 8:27 PM, Tim Kersten <t...@io41.com> wrote: > I'd like to run a data migration on a live server, but only update rows if > the data hasn't changed since I've read it, and would like to do so > optimistically, so without locking the row. Doing so like below works and > prevents me updating rows that have changed since I last read the row. > > Session.query(MyModel).filter_by(foo=old_foo_value).filter_by(bar=old_bar_value).update({'foo': > new_foo_value}) > > While the approach works, it doesn't use the ORM. (I use an after_flush hook > to inspect & log changes from dirty instances in the session). > > Is there a way to update an ORM instance conditionally like above? > > Kindest Regards, > Tim > > -- > 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 http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- 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 http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.