Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rolled back managed transactions before flushing fixtures. #384

Closed
wants to merge 3 commits into from

2 participants

@jdunck
Collaborator

No description provided.

django/test/testcases.py
@@ -557,6 +557,14 @@ def _fixture_teardown(self):
# If the test case has a multi_db=True flag, flush all databases.
# Otherwise, just flush default.
databases = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS]
+
+ # roll back any pending transactions so that we release locks
+ # for the flushes we're about to do.
+ # (otherwise 2 aliases pointing to the same DB could block each other).
+ # see 18984
+ for db in databases:
+ databases[db].rollback_unless_managed()
+
@aaugustin Owner

You want connections[db] here, otherwise it won't work when multi_db = False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@aaugustin
Owner

I have proposed a slightly different patch in Trac. I suggest to continue the discussion over there, since the patch is very small and doesn't really need line-by-line commenting.

@aaugustin aaugustin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 18, 2012
Commits on Nov 20, 2012
  1. Changed to use connections rather than databases.

    Jeremy Dunck authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 django/test/testcases.py
View
8 django/test/testcases.py
@@ -505,6 +505,14 @@ def _fixture_teardown(self):
# If the test case has a multi_db=True flag, flush all databases.
# Otherwise, just flush default.
databases = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS]
+
+ # roll back any pending transactions so that we release locks
+ # for the flushes we're about to do.
+ # (otherwise 2 aliases pointing to the same DB could block each other).
+ # see 18984
+ for db in databases:
+ connections[db].rollback_unless_managed()
+
for db in databases:
call_command('flush', verbosity=0, interactive=False, database=db,
skip_validation=True, reset_sequences=False)
Something went wrong with that request. Please try again.