Index: django/db/transaction.py
===================================================================
--- django/db/transaction.py	(revision 10369)
+++ django/db/transaction.py	(working copy)
@@ -75,7 +75,12 @@
     if dirty.get(thread_ident, False):
         rollback()
         raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
-    dirty[thread_ident] = False
+    if thread_ident in state and len(state[thread_ident]) == 0:
+        del state[thread_ident]
+        if thread_ident in dirty:
+            del dirty[thread_ident]
+        if thread_ident in savepoint_state:
+            del savepoint_state[thread_ident]
 
 def is_dirty():
     """
