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.

Reply via email to