﻿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
12087	"Django ""TransactionTestCase"" isn't"	brandon	nobody	"The Django TransactionTestCase fails to roll back the current database transaction at each test's conclusion, which can leave the current database connection in an unusable state and thus break test isolation.  When Django is using PostgreSQL, and a test deliberately tries violating a database invariant (like inserting an illegal value, or a non-existent primary key) and receives a PostgreSQL runtime error, then all subsequent tests in that test class error out with the failure:

{{{
Traceback (most recent call last):
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/test/testcases.py"", line 242, in __call__
    self._pre_setup()
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/test/testcases.py"", line 217, in _pre_setup
    self._fixture_setup()
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/test/testcases.py"", line 222, in _fixture_setup
    call_command('flush', verbosity=0, interactive=False)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/management/__init__.py"", line 166, in call_command
    return klass.execute(*args, **defaults)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/management/base.py"", line 222, in execute
    output = self.handle(*args, **options)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/management/base.py"", line 351, in handle
    return self.handle_noargs(**options)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/management/commands/flush.py"", line 31, in handle_noargs
    sql_list = sql_flush(self.style, only_django=True)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/management/sql.py"", line 128, in sql_flush
    tables = connection.introspection.django_table_names(only_existing=True)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/__init__.py"", line 510, in django_table_names
    tables = [t for t in tables if self.table_name_converter(t) in self.table_names()]
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/__init__.py"", line 491, in table_names
    return self.get_table_list(cursor)
  File ""/home/brandon/django/v/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/postgresql/introspection.py"", line 30, in get_table_list
    AND pg_catalog.pg_table_is_visible(c.oid)"""""")
InternalError: current transaction is aborted, commands ignored until end of transaction block
}}}

The correction for this is very simple: the _fixture_teardown() method in django.test.testcases.TransactionTestCase needs its code changed from a do-nothing ""pass"" statement to something more effective:

{{{
    def _fixture_teardown(self):
        transaction.rollback()
}}}

With this small change, test isolation is correctly achieved, and the rest of the test cases in the TransactionTestCase class can succeed and fail on their own rather than all dying with the error shown above."		closed	Testing framework	1.1		wontfix		jonathan+django@…	Accepted	1	0	1	0		
