Ticket #6623: commit_manually_exception_pass_thru.diff
File commit_manually_exception_pass_thru.diff, 2.0 KB (added by , 16 years ago) |
---|
-
django/db/transaction.py
58 58 if thread_ident not in dirty: 59 59 dirty[thread_ident] = False 60 60 61 def leave_transaction_management( ):61 def leave_transaction_management(exception=None): 62 62 """ 63 63 Leaves transaction management for a running thread. A dirty flag is carried 64 64 over to the surrounding block, as a commit will commit all changes, even 65 65 those from outside. (Commits are on connection level.) 66 67 If you are leaving a transaction after you've caught an Exception, pass 68 the Exception object to the exception argument and this function will 69 re-raise it for you. 66 70 """ 67 71 thread_ident = thread.get_ident() 68 72 if thread_ident in state and state[thread_ident]: … … 71 75 raise TransactionManagementError("This code isn't under transaction management") 72 76 if dirty.get(thread_ident, False): 73 77 rollback() 74 raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK") 78 if exception: 79 raise exception 80 else: 81 raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK") 75 82 dirty[thread_ident] = False 83 if exception: 84 raise exception 76 85 77 86 def is_dirty(): 78 87 """ … … 219 228 themselves. 220 229 """ 221 230 def _commit_manually(*args, **kw): 231 exp = None 222 232 try: 223 enter_transaction_management() 224 managed(True) 225 return func(*args, **kw) 233 try: 234 enter_transaction_management() 235 managed(True) 236 return func(*args, **kw) 237 except Exception, exp: 238 pass 226 239 finally: 227 leave_transaction_management( )240 leave_transaction_management(exp) 228 241 229 242 return wraps(func)(_commit_manually)