Ticket #17415: 17415.diff

File 17415.diff, 2.1 KB (added by Anssi Kääriäinen, 13 years ago)
  • django/contrib/sites/management.py

    diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py
    index daec3d9..507ecd6 100644
    a b Creates the default Site object.  
    33"""
    44
    55from django.db.models import signals
     6from django.db import connections
    67from django.db import router
    78from django.contrib.sites.models import Site
    89from django.contrib.sites import models as site_app
     10from django.core.management.color import no_style
    911
    1012def create_default_site(app, created_models, verbosity, db, **kwargs):
    1113    # Only create the default sites in databases where Django created the table
    def create_default_site(app, created_models, verbosity, db, **kwargs):  
    1921        # can also crop up outside of tests - see #15346.
    2022        s = Site(pk=1, domain="example.com", name="example.com")
    2123        s.save(using=db)
     24        # Reset the sequence. Above the pk is set explicitly for autofield, so
     25        # make sure the sequence doesn't collide with the above defined ID.
     26        reset_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site])
     27        cursor = connections[db].cursor()
     28        for command in reset_sql:
     29            cursor.execute(command)
    2230    Site.objects.clear_cache()
    2331
    2432signals.post_syncdb.connect(create_default_site, sender=site_app)
  • django/contrib/sites/tests.py

    diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
    index 17ab1f2..4b667b0 100644
    a b class SitesFrameworkTests(TestCase):  
    1515    def tearDown(self):
    1616        Site._meta.installed = self.old_Site_meta_installed
    1717
     18    def test_save_another(self):
     19        """
     20        On some backends the sequence needs reset after save with explicit ID.
     21
     22        Test that there is no sequence collisions by saving another site.
     23        """
     24        Site(domain="example2.com", name="example2.com").save()
     25
    1826    def test_site_manager(self):
    1927        # Make sure that get_current() does not return a deleted Site object.
    2028        s = Site.objects.get_current()
Back to Top