Opened 12 years ago

Closed 12 years ago

#16956 closed Bug (needsinfo)

ContentTypes error in test with master/slave configuration

Reported by: Petr Gorodechnyj <petr.gorodechnyj@…> Owned by: nobody
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords: contenttypes test valueerror
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello.
I get strange "ValueError: list.remove(x): x not in list" when I try to test my project. This happens only with master/slave configuration. If I use single 'default' database everything works ok.
Database configuration:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'dbname',
        'USER': 'gorodechnyj',
        'PASSWORD': 'pass',
        'HOST': 'host',
        'PORT': '5432',
        'TEST_CHARSET': 'UTF-8',
    },
    'slave': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'dbname',
        'USER': 'gorodechnyj',
        'PASSWORD': 'pass',
        'HOST': 'host',
        'PORT': '5432',
        'TEST_CHARSET': 'UTF-8',
        'TEST_MIRROR': 'default'
    }
}
if len(DATABASES) > 1 :
    DATABASE_ROUTERS = ['path.to.MasterSlaveRouter']

Router configuration:

import random

class MasterSlaveRouter(object):
    ''' A router that sets up a simple master/slave configuration '''

    def db_for_read(self, model, **hints):
        return random.choice(['default', 'slave'])

    def db_for_write(self, model, **hints):
        "Point all write operations to the master"
        return 'default'

    def allow_relation(self, obj1, obj2, **hints):
        "Allow any relation between two objects"
        return True

    def allow_syncdb(self, db, model):
        if db == 'default':
            return True
        return False

What I got in case of

python manage.py test

is this stack trace:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 37, in handle
    failures = test_runner.run_tests(test_labels)
  File "/usr/local/lib/python2.7/site-packages/django/test/simple.py", line 359, in run_tests
    old_config = self.setup_databases()
  File "/usr/local/lib/python2.7/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 "/usr/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 366, in create_test_db
    load_initial_data=False)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/contenttypes/management.py", line 25, in update_contenttypes
    content_types.remove(ct)
ValueError: list.remove(x): x not in list

Change History (1)

comment:1 by Aymeric Augustin, 12 years ago

Resolution: needsinfo
Status: newclosed

This code was rewritten in r16739. Could you check if the problem still occurs with a recent svn checkout? Please reopen the ticket if it does.

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