Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rolled back managed transactions before flushing fixtures. #384

Closed
wants to merge 3 commits into from

2 participants

Jeremy Dunck Aymeric Augustin
Jeremy Dunck
Owner

No description provided.

django/test/testcases.py
@@ -557,6 +557,14 @@ def _fixture_teardown(self):
557 557
         # If the test case has a multi_db=True flag, flush all databases.
558 558
         # Otherwise, just flush default.
559 559
         databases = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS]
  560
+
  561
+        # roll back any pending transactions so that we release locks 
  562
+        # for the flushes we're about to do.
  563
+        #  (otherwise 2 aliases pointing to the same DB could block each other).
  564
+        # see 18984
  565
+        for db in databases:
  566
+            databases[db].rollback_unless_managed()
  567
+
1
Aymeric Augustin 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
Aymeric Augustin
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.

Aymeric Augustin aaugustin closed this November 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 0 deletions. Show diff stats Hide diff stats

  1. 8  django/test/testcases.py
8  django/test/testcases.py
@@ -505,6 +505,14 @@ def _fixture_teardown(self):
505 505
         # If the test case has a multi_db=True flag, flush all databases.
506 506
         # Otherwise, just flush default.
507 507
         databases = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS]
  508
+
  509
+        # roll back any pending transactions so that we release locks 
  510
+        # for the flushes we're about to do.
  511
+        #  (otherwise 2 aliases pointing to the same DB could block each other).
  512
+        # see 18984
  513
+        for db in databases:
  514
+            connections[db].rollback_unless_managed()
  515
+
508 516
         for db in databases:
509 517
             call_command('flush', verbosity=0, interactive=False, database=db,
510 518
                          skip_validation=True, reset_sequences=False)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.