python - Context manager, multiple function calls and transactions -
say do:
with my_connection: o.first_call()
where my_connection
's __exit__
method calls rollback
and o.first_call
in execution calls j.second_call
, calls z.third_call
. z.third_call
inserted record in database, j.second_call
inserts record, o.first_call
craps out. rollback state before first entered context of my_connection or rollbacked state between o.first_call
, j.second_call
?
edit: clear, i'm hoping entire thing gets rolled before ever called o.first_call
edit2: i'm hoping if there magic in __enter__
, kind of context say, whatever called 1 big transaction.
transactions rolled-back last commit
call.
per database api specification v2.0:
.commit()
commit pending transaction database.
.rollback()
... causes database roll start of pending transaction.
so depends on mean "successfully inserted". if insertion finalized call commit
, rollback not remove insertion. however, if there no commit, insertion rolled-back.
Comments
Post a Comment