Ticket #6623: commit_manually_better_error_message.diff
File commit_manually_better_error_message.diff, 2.0 KB (added by , 17 years ago) |
---|
-
django/db/transaction.py
54 54 if thread_ident not in dirty: 55 55 dirty[thread_ident] = False 56 56 57 def leave_transaction_management( ):57 def leave_transaction_management(debug_message=''): 58 58 """ 59 59 Leaves transaction management for a running thread. A dirty flag is carried 60 60 over to the surrounding block, as a commit will commit all changes, even 61 61 those from outside. (Commits are on connection level.) 62 63 If the transaction management gets left, because an exception was raised, it is hard 64 to find root of the problem. The debug_message gets added to the TransactionManagementError, 65 if it gets raised. See decorator commit_manually. 62 66 """ 63 67 thread_ident = thread.get_ident() 64 68 if thread_ident in state and state[thread_ident]: … … 67 71 raise TransactionManagementError("This code isn't under transaction management") 68 72 if dirty.get(thread_ident, False): 69 73 rollback() 70 raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK ")74 raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK %s" % (debug_message)) 71 75 dirty[thread_ident] = False 72 76 73 77 def is_dirty(): … … 212 216 themselves. 213 217 """ 214 218 def _commit_manually(*args, **kw): 219 debug_message='' 215 220 try: 216 221 enter_transaction_management() 217 222 managed(True) 218 223 return func(*args, **kw) 224 except Exception, exc: 225 import logging 226 logging.error('ok') 227 import sys, traceback 228 etype, value, tb = sys.exc_info() 229 debug_message='%r: %s' % (exc, ''.join(traceback.format_exception(etype, value, tb))) 219 230 finally: 220 leave_transaction_management( )231 leave_transaction_management(debug_message) 221 232 222 233 return _commit_manually