﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10744	transaction.leave_transaction_management leaks	Glenn Maynard	Aymeric Augustin	"leave_transaction_management removes threads from state, but not dirty.  This will cause a leak as threads are destroyed, and causes the set_clean and set_dirty sanity check (""This code isn't under transaction management"") to not always trigger.  It may also cause problems if created threads get the same thread identifier as a previous thread.  Attached patch cleans up the transaction state when exiting transaction management; obviously, TLS would be a cleaner and more reliable solution.

This patch causes a failure in regressiontests.cache.tests.DBCacheTests:

{{{
======================================================================
ERROR: test_add (regressiontests.cache.tests.DBCacheTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/home/glenn/django/tests/regressiontests/cache/tests.py"", line 142, in test_add
    result = self.cache.add(""addkey1"", ""newvalue"")
  File ""/home/glenn/django/django/core/cache/backends/db.py"", line 45, in add
    return self._base_set('add', key, value, timeout)
  File ""/home/glenn/django/django/core/cache/backends/db.py"", line 68, in _base_set
    transaction.rollback()
  File ""/home/glenn/django/django/db/transaction.py"", line 180, in rollback
    set_clean()
  File ""/home/glenn/django/django/db/transaction.py"", line 114, in set_clean
    raise TransactionManagementError(""This code isn't under transaction management"")
TransactionManagementError: This code isn't under transaction management
}}}

I don't know what _base_set should be doing, but it seems like this error is intended to be triggered in this situation.
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	1	0	0
