Skip to content

Commit

Permalink
fix: transaction error in with statement
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Dec 15, 2007
1 parent 247d501 commit a9df657
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,13 @@ class transaction:
end.
"""
def __enter__(self):
self.db_transaction = web.ctx.db_transaction
transact()

def __exit__(self, exctype, excvalue, traceback):
if exctype is not None:
rollback()
while self.db_transaction < web.ctx.db_transaction:
rollback()
else:
commit()

Expand Down Expand Up @@ -400,7 +402,7 @@ def rollback(care=True):
"""Rolls back a transaction."""
web.ctx.db_transaction -= 1
if web.ctx.db_transaction < 0:
web.db_transaction = 0
web.ctx.db_transaction = 0
if care:
raise TransactionError, "not in a transaction"
else:
Expand Down

0 comments on commit a9df657

Please sign in to comment.