I'm trying to figure out how to structure my code so transactions do
the right thing when exceptions are raised. So far I've got
def update(self):
hub.begin()
self.modify_database()
if i_dont_like_things:
hub.rollback()
else:
hub.commit()
hub.end()
Is there any way to have a rollback happend automatically if
modify_database raises an exception? Or do I need to wrap everything
in a try/except to guarantee a rollback (and I assume I would also need
a hub.end() in there as well).
I'm thinking of the feature in some systems where you aquire a
transaction object which will automatically do a rollback if it goes
out of scope without a commit. Somthing like:
trans = hub.begin()
do_work()
trans.commit()
--
DS