Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensured that the test suite creates the default DB before any others.

Refs #14799. Technically this fixes the problem, but I'm far from convinced
it's the perfect solution, so I'm leaving the ticket open. I'm committing
this now because it's the minimum required to get the test suite running
again, but this commit can -- and probably should -- be reverted in favor of
a more holistic fix later on.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14756 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2fa22a4b6414235a38fa646b2c6e17e49630185f 1 parent 0714b0f
@jacobian jacobian authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 django/test/simple.py
View
18 django/test/simple.py
@@ -216,7 +216,7 @@ def build_suite(self, test_labels, extra_tests=None, **kwargs):
return reorder_suite(suite, (TestCase,))
def setup_databases(self, **kwargs):
- from django.db import connections
+ from django.db import connections, DEFAULT_DB_ALIAS
# First pass -- work out which databases actually need to be created,
# and which ones are test mirrors or duplicate entries in DATABASES
@@ -238,11 +238,21 @@ def setup_databases(self, **kwargs):
connection.settings_dict['ENGINE'],
connection.settings_dict['NAME'],
), []).append(alias)
-
- # Second pass -- actually create the databases.
+
+ # Re-order the list of databases to create, making sure the default
+ # database is first. Otherwise, creation order is semi-random (i.e.
+ # dict ordering dependent).
+ dbs_to_create = []
+ for dbinfo, aliases in test_databases.items():
+ if DEFAULT_DB_ALIAS in aliases:
+ dbs_to_create.insert(0, (dbinfo, aliases))
+ else:
+ dbs_to_create.append((dbinfo, aliases))
+
+ # Final pass -- actually create the databases.
old_names = []
mirrors = []
- for (host, port, engine, db_name), aliases in test_databases.items():
+ for (host, port, engine, db_name), aliases in dbs_to_create:
# Actually create the database for the first connection
connection = connections[aliases[0]]
old_names.append((connection, db_name, True))
Please sign in to comment.
Something went wrong with that request. Please try again.