Skip to content

Loading…

Rolled back managed transactions before flushing fixtures. #384

Closed
wants to merge 3 commits into from

2 participants

@jdunck
Django member

No description provided.

@aaugustin aaugustin commented on an outdated diff
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 Django member

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
Django member

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 committed
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.