Code

Ticket #16353: 16353.2.diff

File 16353.2.diff, 3.2 KB (added by aaugustin, 3 years ago)
Line 
1Index: django/db/backends/creation.py
2===================================================================
3--- django/db/backends/creation.py      (révision 16855)
4+++ django/db/backends/creation.py      (copie de travail)
5@@ -248,14 +248,6 @@
6             interactive=False,
7             database=self.connection.alias)
8 
9-        # One effect of calling syncdb followed by flush is that the id of the
10-        # default site may or may not be 1, depending on how the sequence was
11-        # reset.  If the sites app is loaded, then we coerce it.
12-        from django.db.models import get_model
13-        Site = get_model('sites', 'Site')
14-        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
15-            Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
16-
17         from django.core.cache import get_cache
18         from django.core.cache.backends.db import BaseDatabaseCache
19         for cache_alias in settings.CACHES:
20Index: django/contrib/gis/db/backends/spatialite/creation.py
21===================================================================
22--- django/contrib/gis/db/backends/spatialite/creation.py       (révision 16855)
23+++ django/contrib/gis/db/backends/spatialite/creation.py       (copie de travail)
24@@ -56,14 +56,6 @@
25             interactive=False,
26             database=self.connection.alias)
27 
28-        # One effect of calling syncdb followed by flush is that the id of the
29-        # default site may or may not be 1, depending on how the sequence was
30-        # reset.  If the sites app is loaded, then we coerce it.
31-        from django.db.models import get_model
32-        Site = get_model('sites', 'Site')
33-        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
34-            Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
35-
36         from django.core.cache import get_cache
37         from django.core.cache.backends.db import BaseDatabaseCache
38         for cache_alias in settings.CACHES:
39Index: django/contrib/sites/management.py
40===================================================================
41--- django/contrib/sites/management.py  (révision 16855)
42+++ django/contrib/sites/management.py  (copie de travail)
43@@ -3,14 +3,21 @@
44 """
45 
46 from django.db.models import signals
47+from django.db import router
48 from django.contrib.sites.models import Site
49 from django.contrib.sites import models as site_app
50 
51 def create_default_site(app, created_models, verbosity, db, **kwargs):
52-    if Site in created_models:
53+    # Only create the default sites in databases where Django created the table
54+    if Site in created_models and router.allow_syncdb(db, Site) :
55         if verbosity >= 2:
56             print "Creating example.com Site object"
57-        s = Site(domain="example.com", name="example.com")
58+        # Django's test suite sets settings.SITE_ID = 1, and several tests
59+        # rely on this value. However, during the creation of the databases
60+        # for the tests, syncdb is called followed by flush. Depending on
61+        # how the autoincrementing sequences are reset, it isn't guaranteed
62+        # that the next id will be 1, so we coerce it. See #15573 and #16353.
63+        s = Site(pk=1, domain="example.com", name="example.com")
64         s.save(using=db)
65     Site.objects.clear_cache()
66