summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2011-09-21 22:58:15 +0000
committerCarl Meyer <carl@oddbird.net>2011-09-21 22:58:15 +0000
commit65942eb31f448f6ac1cc16b8ff29b18253fa103d (patch)
tree04271a2f325dd6a9ad803503b8de368c8f552985 /django
parent3606f1f7b2eb422a49944824b1d8dbc227dc879f (diff)
downloaddjango-65942eb31f448f6ac1cc16b8ff29b18253fa103d.tar.gz
[1.3.X] Fixed #16353 -- don't try to create Site objects on all databases. Refs #15573, #15346. Thanks Aymeric Augustin for the report and the patch.
Backport of r16868 in trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16869 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/db/backends/spatialite/creation.py8
-rw-r--r--django/contrib/sites/management.py11
-rw-r--r--django/db/backends/creation.py9
3 files changed, 9 insertions, 19 deletions
diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py
index c107d96e72..ee5f9db336 100644
--- a/django/contrib/gis/db/backends/spatialite/creation.py
+++ b/django/contrib/gis/db/backends/spatialite/creation.py
@@ -56,14 +56,6 @@ class SpatiaLiteCreation(DatabaseCreation):
interactive=False,
database=self.connection.alias)
- # One effect of calling syncdb followed by flush is that the id of the
- # default site may or may not be 1, depending on how the sequence was
- # reset. If the sites app is loaded, then we coerce it.
- from django.db.models import get_model
- Site = get_model('sites', 'Site')
- if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
- Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
-
from django.core.cache import get_cache
from django.core.cache.backends.db import BaseDatabaseCache
for cache_alias in settings.CACHES:
diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
index 19872740ee..daec3d9eec 100644
--- a/django/contrib/sites/management.py
+++ b/django/contrib/sites/management.py
@@ -3,14 +3,21 @@ Creates the default Site object.
"""
from django.db.models import signals
+from django.db import router
from django.contrib.sites.models import Site
from django.contrib.sites import models as site_app
def create_default_site(app, created_models, verbosity, db, **kwargs):
- if Site in created_models:
+ # Only create the default sites in databases where Django created the table
+ if Site in created_models and router.allow_syncdb(db, Site) :
if verbosity >= 2:
print "Creating example.com Site object"
- s = Site(domain="example.com", name="example.com")
+ # 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
+ # the next id will be 1, so we coerce it. See #15573 and #16353. This
+ # can also crop up outside of tests - see #15346.
+ s = Site(pk=1, domain="example.com", name="example.com")
s.save(using=db)
Site.objects.clear_cache()
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index 57e3f7762d..ef594b7bfc 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -374,15 +374,6 @@ class BaseDatabaseCreation(object):
verbosity=max(verbosity - 1, 0),
interactive=False,
database=self.connection.alias)
-
- # One effect of calling syncdb followed by flush is that the id of the
- # default site may or may not be 1, depending on how the sequence was
- # reset. If the sites app is loaded, then we coerce it.
- from django.db.models import get_model
- if 'django.contrib.sites' in settings.INSTALLED_APPS:
- Site = get_model('sites', 'Site')
- if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
- Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
from django.core.cache import get_cache
from django.core.cache.backends.db import BaseDatabaseCache