Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16353 -- don't try to create Site objects on all databases. Re…

…fs #15573, #15346. Thanks Aymeric Augustin for the report and the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16868 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f91af7252352459cc84dc5da8b367f4c571c9a31 1 parent cfadc36
Carl Meyer authored September 21, 2011
8  django/contrib/gis/db/backends/spatialite/creation.py
@@ -56,14 +56,6 @@ def create_test_db(self, verbosity=1, autoclobber=False):
56 56
             interactive=False,
57 57
             database=self.connection.alias)
58 58
 
59  
-        # One effect of calling syncdb followed by flush is that the id of the
60  
-        # default site may or may not be 1, depending on how the sequence was
61  
-        # reset.  If the sites app is loaded, then we coerce it.
62  
-        from django.db.models import get_model
63  
-        Site = get_model('sites', 'Site')
64  
-        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
65  
-            Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
66  
-
67 59
         from django.core.cache import get_cache
68 60
         from django.core.cache.backends.db import BaseDatabaseCache
69 61
         for cache_alias in settings.CACHES:
11  django/contrib/sites/management.py
@@ -3,14 +3,21 @@
3 3
 """
4 4
 
5 5
 from django.db.models import signals
  6
+from django.db import router
6 7
 from django.contrib.sites.models import Site
7 8
 from django.contrib.sites import models as site_app
8 9
 
9 10
 def create_default_site(app, created_models, verbosity, db, **kwargs):
10  
-    if Site in created_models:
  11
+    # Only create the default sites in databases where Django created the table
  12
+    if Site in created_models and router.allow_syncdb(db, Site) :
11 13
         if verbosity >= 2:
12 14
             print "Creating example.com Site object"
13  
-        s = Site(domain="example.com", name="example.com")
  15
+        # The default settings set SITE_ID = 1, and some tests in Django's test
  16
+        # suite rely on this value. However, if database sequences are reused
  17
+        # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
  18
+        # the next id will be 1, so we coerce it. See #15573 and #16353. This
  19
+        # can also crop up outside of tests - see #15346.
  20
+        s = Site(pk=1, domain="example.com", name="example.com")
14 21
         s.save(using=db)
15 22
     Site.objects.clear_cache()
16 23
 
8  django/db/backends/creation.py
@@ -248,14 +248,6 @@ def create_test_db(self, verbosity=1, autoclobber=False):
248 248
             interactive=False,
249 249
             database=self.connection.alias)
250 250
 
251  
-        # One effect of calling syncdb followed by flush is that the id of the
252  
-        # default site may or may not be 1, depending on how the sequence was
253  
-        # reset.  If the sites app is loaded, then we coerce it.
254  
-        from django.db.models import get_model
255  
-        Site = get_model('sites', 'Site')
256  
-        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
257  
-            Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
258  
-
259 251
         from django.core.cache import get_cache
260 252
         from django.core.cache.backends.db import BaseDatabaseCache
261 253
         for cache_alias in settings.CACHES:

0 notes on commit f91af72

Please sign in to comment.
Something went wrong with that request. Please try again.