I need to get all rows that were affected by a bulk delete like that:
Session.query(SomeClass).filter_by(foo='bar').delete()
I found the possibility to subscribe to bulk delete events but can’t figure out how I can use this event to actually get the information I need.
Okay, found the answer \☺/ You can re-execute the select statement that was used to select the rows for bulk deletion. Unfortunately you can’t query the ORM objects, but you can get a list of all the deleted rows with the old column values as tuples: