Opened 9 years ago

Closed 9 years ago

Last modified 6 years ago

#16828 closed Bug (duplicate)

Upgrade from 1.3 to 1.3.1 breaks test with multiple databases

Reported by: Aymeric Augustin Owned by: nobody
Component: Testing framework Version: 1.3
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


To reproduce this problem:

  • startproject regrtest && cd regrtest
  • create a file called with this content (this is a dummy router that puts everything in the "default" database):
    class TestRouter(object):
        def db_for_read(self, model, **hints):
            return 'default'
        def db_for_write(self, model, **hints):
            return 'default'
        def allow_relation(self, obj1, obj2, **hints):
            return True
        def allow_syncdb(self, db, model):
            return db == 'default'
  • in, replace the default value of DATABASES with this content:
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'default.sqlite3',
        'other': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'other.sqlite3',
    DATABASE_ROUTERS = ['routers.TestRouter']
  • python test auth works under 1.3 but not under 1.3.1:
    aaugustin@aaugustin regrtest % . ../dj13_venv/bin/activate
    (dj13_venv)aaugustin@aaugustin regrtest % python test auth
    Creating test database for alias 'default'...
    Creating test database for alias 'other'...
    Ran 98 tests in 1.745s
    Destroying test database for alias 'default'...
    Destroying test database for alias 'other'...
    (dj13_venv)aaugustin@aaugustin regrtest % . ../dj131_venv/bin/activate
    (dj131_venv)aaugustin@aaugustin regrtest % python test auth
    Creating test database for alias 'default'...
    Creating test database for alias 'other'...
    Traceback (most recent call last):
      File "", line 14, in <module>
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/", line 438, in execute_manager
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/", line 379, in execute
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/", line 191, in run_from_argv
        self.execute(*args, **options.__dict__)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/", line 220, in execute
        output = self.handle(*args, **options)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/commands/", line 37, in handle
        failures = test_runner.run_tests(test_labels)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/test/", line 359, in run_tests
        old_config = self.setup_databases()
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/test/", line 296, in setup_databases
        test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/backends/", line 384, in create_test_db
        if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/models/", line 334, in count
        return self.query.get_count(using=self.db)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/models/sql/", line 401, in get_count
        number = obj.get_aggregation(using=using)[None]
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/models/sql/", line 367, in get_aggregation
        result = query.get_compiler(using).execute_sql(SINGLE)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/models/sql/", line 735, in execute_sql
        cursor.execute(sql, params)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/db/backends/sqlite3/", line 234, in execute
        return Database.Cursor.execute(self, query, params)
    django.db.utils.DatabaseError: no such table: django_site

Apparently, the origin of the problem is that Django attempts to create a default site object in the "other" database.

NB: for this test, I created two virtualenvs, dj13_venv and dj131_venv, with a fresh copy of Django 1.3 and 1.3.1 respectively:

aaugustin@aaugustin dev % virtualenv-2.6 --no-site-packages dj13_venv
New python executable in dj13_venv/bin/python
Installing setuptools............done.
Installing pip...............done.
aaugustin@aaugustin dev % . ./dj13_venv/bin/activate
(dj13_venv)aaugustin@aaugustin dev % pip install django==1.3
Downloading/unpacking django==1.3
  Downloading Django-1.3.tar.gz (6.5Mb): 6.5Mb downloaded
  Running egg_info for package django
Installing collected packages: django
  Running install for django
    changing mode of build/scripts-2.6/ from 644 to 755
    changing mode of /Users/aaugustin/Documents/dev/dj13_venv/bin/ to 755
Successfully installed django
Cleaning up...

Attachments (1)

16828.diff (1.5 KB) - added by Aymeric Augustin 9 years ago.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Aymeric Augustin

Attachment: 16828.diff added

comment:1 Changed 9 years ago by Aymeric Augustin

Has patch: set
Needs tests: set

comment:2 Changed 9 years ago by Aymeric Augustin

This bug also exists on trunk.

comment:3 Changed 9 years ago by Julien Phalip

Isn't this a duplicate of #16353?

comment:4 Changed 9 years ago by Julien Phalip

Or maybe is it a bug in trunk that has also been introduced in the 1.3.1 release?

comment:5 Changed 9 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

Yeah, I think I just managed to report the same bug twice... and write exactly the same patch... *goes grab a coffee*.

For the record, this problem was introduced in r16027 (trunk) and r16028 (1.3.X).

comment:6 Changed 6 years ago by Tim Graham <timograham@…>

In 1f98ec2e53e4636863396ab54f671f4546f9ba4c:

Fixed #23929 -- Added more tests for create_default_site.

Refs: #15346, #15573, #16353, #16828.

Note: See TracTickets for help on using tickets.
Back to Top