Commit bfc75996 authored by wrwrwr's avatar wrwrwr Committed by Tim Graham
Browse files

Fixed #23945 -- Made default site use the configured SITE_ID.

parent 1739ae9e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ Creates the default Site object.
"""

from django.apps import apps
from django.conf import settings
from django.core.management.color import no_style
from django.db import DEFAULT_DB_ALIAS, connections, router

@@ -24,7 +25,7 @@ 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=settings.SITE_ID, domain="example.com", name="example.com").save(using=db)

        # We set an explicit pk instead of relying on auto-incrementation,
        # so we need to reset the database sequence. See #17415.
+8 −0
Original line number Diff line number Diff line
@@ -176,6 +176,14 @@ class CreateDefaultSiteTests(TestCase):
        post_migrate.send(sender=self.app_config, app_config=self.app_config, verbosity=0)
        self.assertTrue(Site.objects.exists())

    @override_settings(SITE_ID=35696)
    def test_custom_site_id(self):
        """
        #23945 - The configured ``SITE_ID`` should be respected.
        """
        create_default_site(self.app_config, verbosity=0)
        self.assertEqual(Site.objects.get().pk, 35696)


class MiddlewareTest(TestCase):

+4 −0
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@ Minor features
  <django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not
  defined.

* The default :class:`~django.contrib.sites.models.Site` created when running
  ``migrate`` now respects the :setting:`SITE_ID` setting (instead of always
  using ``pk=1``).

:mod:`django.contrib.staticfiles`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^