Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#16828 closed Bug (duplicate)

Upgrade from 1.3 to 1.3.1 breaks manage.py 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

Description

To reproduce this problem:

  • django-admin.py startproject regrtest && cd regrtest
  • create a file called routers.py 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 settings.py, replace the default value of DATABASES with this content:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'default.sqlite3',
        },
        'other': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'other.sqlite3',
        },
    }
    
    DATABASE_ROUTERS = ['routers.TestRouter']
    
  • python manage.py 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 manage.py test auth
    Creating test database for alias 'default'...
    Creating test database for alias 'other'...
    ..................................................................................................
    ----------------------------------------------------------------------
    Ran 98 tests in 1.745s
    
    OK
    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 manage.py test auth
    Creating test database for alias 'default'...
    Creating test database for alias 'other'...
    Traceback (most recent call last):
      File "manage.py", line 14, in <module>
        execute_manager(settings)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
        utility.execute()
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/core/management/base.py", 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/base.py", 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/test.py", 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/simple.py", line 359, in run_tests
        old_config = self.setup_databases()
      File "/Users/aaugustin/Documents/dev/dj131_venv/lib/python2.6/site-packages/django/test/simple.py", 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/creation.py", 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/query.py", 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/query.py", 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/query.py", 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/compiler.py", 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/base.py", 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 setup.py egg_info for package django
Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-2.6/django-admin.py from 644 to 755
    changing mode of /Users/aaugustin/Documents/dev/dj13_venv/bin/django-admin.py to 755
Successfully installed django
Cleaning up...

Attachments (1)

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

Download all attachments as: .zip

Change History (7)

by Aymeric Augustin, 13 years ago

Attachment: 16828.diff added

comment:1 by Aymeric Augustin, 13 years ago

Has patch: set
Needs tests: set

comment:2 by Aymeric Augustin, 13 years ago

This bug also exists on trunk.

comment:3 by Julien Phalip, 13 years ago

Isn't this a duplicate of #16353?

comment:4 by Julien Phalip, 13 years ago

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

comment:5 by Aymeric Augustin, 13 years ago

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 by Tim Graham <timograham@…>, 10 years ago

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