summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-02-12 13:58:37 -0500
committerTim Graham <timograham@gmail.com>2015-02-13 07:08:49 -0500
commit1b93b0977d2fa7d3cca2fb64168655582e7a88f9 (patch)
tree9b14a9186ec07e56ef12d474ba297fdad3baea83 /django
parent5697a4c9cfb70962ddf90099214b2d69a6ae27b7 (diff)
[1.7.x] Fixed #24332 -- Fixed contrib.sites create_default_site() when 'default' DATABASES is empty.
Backport of e8cf4f8abec87b9da6ed8e5c8cf833af9b27f4dd from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/sites/management.py2
-rw-r--r--django/contrib/sites/tests.py9
2 files changed, 9 insertions, 2 deletions
diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index 99ec79395f..b3a8347c14 100644
--- a/django/contrib/sites/management.py
+++ b/django/contrib/sites/management.py
@@ -17,7 +17,7 @@ def create_default_site(app_config, verbosity=2, interactive=True, using=DEFAULT
if not router.allow_migrate(using, Site):
return
- if not Site.objects.exists():
+ if not Site.objects.using(using).exists():
# The default settings set SITE_ID = 1, and some tests in Django's test
# suite rely on this value. However, if database sequences are reused
# (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 0e704763eb..e9f68c8727 100644
--- a/django/contrib/sites/tests.py
+++ b/django/contrib/sites/tests.py
@@ -107,7 +107,7 @@ class CreateDefaultSiteTests(TestCase):
self.assertEqual(Site.objects.count(), 1)
@unittest.skipIf('other' not in connections, "Requires 'other' database connection.")
- def test_multi_db(self):
+ def test_multi_db_with_router(self):
"""
#16353, #16828 - The default site creation should respect db routing.
"""
@@ -121,6 +121,13 @@ class CreateDefaultSiteTests(TestCase):
finally:
router.routers = old_routers
+ @unittest.skipIf('other' not in connections, "Requires 'other' database connection.")
+ def test_multi_db(self):
+ create_default_site(self.app_config, using='default', verbosity=0)
+ create_default_site(self.app_config, using='other', verbosity=0)
+ self.assertTrue(Site.objects.using('default').exists())
+ self.assertTrue(Site.objects.using('other').exists())
+
def test_save_another(self):
"""
#17415 - Another site can be created right after the default one.