﻿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
6820	Error in django/core/management/commands/flush.py prevents runtests.py from running successfully under PostgreSQL 8.3	tpherndon	Jacob	"With qs-rf 7297, I attempt to run runtests.py using PostgreSQL 8.3, and the tests fail with the following message:
{{{
Doctest: modeltests.field_subclassing.models.__test__.API_TESTS ... ok
Error: Database test_synapse couldn't be flushed. Possible reasons:
      * The database isn't running or isn't configured correctly.
      * At least one of the expected database tables doesn't exist.
      * The SQL was invalid.
    Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
    The full error: cannot TRUNCATE ""generic_relations_taggeditem"" because it is being used by active queries in this session
}}}

The error is caused by the modeltests.fixtures test, and happens because there are non-core-django tables that are related to django-core tables that are being flushed by the command:
{{{
# Reset the database representation of this app.
# This will return the database to a clean initial state.
>>> management.call_command('flush', verbosity=0, interactive=False)
}}}

Since there are relationships between these tables and the django-core tables, the flush of the django-core tables fails, causing the test run to crash.  The attached patch changes the sql_flush to affect more than the only_django tables, which allows for completion of runtests.py on PostgreSQL 8.3 with one error:
{{{
======================================================================
ERROR: Shortcuts for an object that has with a get_absolute_url method raises 404
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/herndonp/Downloads/django-qsrf/tests/regressiontests/views/tests/defaults.py"", line 23, in test_shortcut_no_absolute_url
    for obj in Article.objects.all():
  File ""/Library/Python/2.5/site-packages/django/db/models/query.py"", line 66, in _result_iter
    self._fill_cache()
  File ""/Library/Python/2.5/site-packages/django/db/models/query.py"", line 455, in _fill_cache
    self._result_cache.append(self._iter.next())
  File ""/Library/Python/2.5/site-packages/django/db/models/query.py"", line 147, in iterator
    for row in self.query.results_iter():
  File ""/Library/Python/2.5/site-packages/django/db/models/sql/query.py"", line 168, in results_iter
    for rows in self.execute_sql(MULTI):
  File ""/Library/Python/2.5/site-packages/django/db/models/sql/query.py"", line 1348, in <lambda>
    return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
InterfaceError: cursor already closed

----------------------------------------------------------------------
Ran 240 tests in 724.716s

FAILED (errors=1)
Destroying test database...
}}}

The change allows run-to-completion with no errors on sqlite and mysql."		closed	Core (Other)	dev		fixed		Russell Keith-Magee john@…	Accepted	1	0	0	1	0	0
