summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-12-27 09:06:38 -0500
committerTim Graham <timograham@gmail.com>2014-12-27 10:29:21 -0500
commita79012f6d88a8cd67bd35c54b91d826f2b7a4cb2 (patch)
tree7b492e4dd8c4ef1646010c439c5a7e8734e11a3e
parent965a999ae5a03ca595f3842feacfbce5dc12f20a (diff)
[1.7.x] Fixed #24000 -- Corrected contrib.sites default site creation in a multiple database setup.
Backport of 89e2c60f4396241c667b7a1de37765b7c96d702f from master
-rw-r--r--django/contrib/sites/management.py10
-rw-r--r--django/contrib/sites/tests.py4
-rw-r--r--docs/releases/1.7.2.txt3
3 files changed, 10 insertions, 7 deletions
diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index 8353a6f496..99ec79395f 100644
--- a/django/contrib/sites/management.py
+++ b/django/contrib/sites/management.py
@@ -8,13 +8,13 @@ from django.db import DEFAULT_DB_ALIAS, connections, router
from django.db.models import signals
-def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs):
+def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
try:
Site = apps.get_model('sites', 'Site')
except LookupError:
return
- if not router.allow_migrate(db, Site):
+ if not router.allow_migrate(using, Site):
return
if not Site.objects.exists():
@@ -25,15 +25,15 @@ def create_default_site(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
# can also crop up outside of tests - see #15346.
if verbosity >= 2:
print("Creating example.com Site object")
- Site(pk=1, domain="example.com", name="example.com").save(using=db)
+ Site(pk=1, domain="example.com", name="example.com").save(using=using)
# We set an explicit pk instead of relying on auto-incrementation,
# so we need to reset the database sequence. See #17415.
- sequence_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site])
+ sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site])
if sequence_sql:
if verbosity >= 2:
print("Resetting sequence")
- with connections[db].cursor() as cursor:
+ with connections[using].cursor() as cursor:
for command in sequence_sql:
cursor.execute(command)
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index d6eae94928..e59eb64e02 100644
--- a/django/contrib/sites/tests.py
+++ b/django/contrib/sites/tests.py
@@ -111,8 +111,8 @@ class CreateDefaultSiteTests(TestCase):
old_routers = router.routers
router.routers = [JustOtherRouter()]
try:
- create_default_site(self.app_config, db='default', verbosity=0)
- create_default_site(self.app_config, db='other', verbosity=0)
+ create_default_site(self.app_config, using='default', verbosity=0)
+ create_default_site(self.app_config, using='other', verbosity=0)
self.assertFalse(Site.objects.using('default').exists())
self.assertTrue(Site.objects.using('other').exists())
finally:
diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt
index fb42512166..31a96a4ccd 100644
--- a/docs/releases/1.7.2.txt
+++ b/docs/releases/1.7.2.txt
@@ -172,3 +172,6 @@ Bugfixes
(:ticket:`24054`).
* Added tablespace SQL to apps with migrations (:ticket:`24051`).
+
+* Corrected ``contrib.sites`` default site creation in a multiple database
+ setup (:ticket:`24000`).