Index: django/db/transaction.py
===================================================================
--- django/db/transaction.py	(Revision 7135)
+++ django/db/transaction.py	(Arbeitskopie)
@@ -54,11 +54,15 @@
     if thread_ident not in dirty:
         dirty[thread_ident] = False
 
-def leave_transaction_management():
+def leave_transaction_management(debug_message=''):
     """
     Leaves transaction management for a running thread. A dirty flag is carried
     over to the surrounding block, as a commit will commit all changes, even
     those from outside. (Commits are on connection level.)
+
+    If the transaction management gets left, because an exception was raised, it is hard
+    to find root of the problem. The debug_message gets added to the TransactionManagementError,
+    if it gets raised. See decorator commit_manually.
     """
     thread_ident = thread.get_ident()
     if thread_ident in state and state[thread_ident]:
@@ -67,7 +71,7 @@
         raise TransactionManagementError("This code isn't under transaction management")
     if dirty.get(thread_ident, False):
         rollback()
-        raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
+        raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK %s" % (debug_message))
     dirty[thread_ident] = False
 
 def is_dirty():
@@ -212,11 +216,18 @@
     themselves.
     """
     def _commit_manually(*args, **kw):
+        debug_message=''
         try:
             enter_transaction_management()
             managed(True)
             return func(*args, **kw)
+        except Exception, exc:
+            import logging
+            logging.error('ok')
+            import sys, traceback
+            etype, value, tb = sys.exc_info()
+            debug_message='%r: %s' % (exc, ''.join(traceback.format_exception(etype, value, tb)))
         finally:
-            leave_transaction_management()
+            leave_transaction_management(debug_message)
 
     return _commit_manually
