Monday, May 23, 2011

Multi-database and master/slave configuration

i have a fairly complex database configuration and think i've found a
bug. i have a master/slave "default" database with an appropriate
router and then 2 other data databases which also have their own
django router. everything works fine on production, but when trying to
run unit tests if fails with

Traceback (most recent call last):
File "./27.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/
__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/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/lib/python2.7/site-packages/django/core/management/
base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/
base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/south/management/commands/
test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/core/management/
commands/test.py", line 37, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/lib/python2.7/site-packages/django/test/simple.py", line
396, in run_tests
old_config = self.setup_databases()
File "/usr/lib/python2.7/site-packages/django/test/simple.py", line
334, in setup_databases
test_db_name = connection.creation.create_test_db(self.verbosity,
autoclobber=not self.interactive)
File "/usr/lib/python2.7/site-packages/django/db/backends/
creation.py", line 357, in create_test_db
load_initial_data=False)
File "/usr/lib/python2.7/site-packages/django/core/management/
__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/usr/lib/python2.7/site-packages/django/core/management/
base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/
base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.7/site-packages/django/core/management/
commands/syncdb.py", line 107, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/lib/python2.7/site-packages/django/core/management/
sql.py", line 182, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/python2.7/site-packages/django/dispatch/
dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/python2.7/site-packages/django/contrib/contenttypes/
management.py", line 25, in update_contenttypes
ct.save()
File "/usr/lib/python2.7/site-packages/django/db/models/base.py",
line 458, in save
self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
File "/usr/lib/python2.7/site-packages/django/db/models/base.py",
line 551, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/python2.7/site-packages/django/db/models/manager.py",
line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.7/site-packages/django/db/models/query.py",
line 1524, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/
compiler.py", line 788, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/python2.7/site-packages/django/db/models/sql/
compiler.py", line 732, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/
base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line
174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py",
line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.IntegrityError: (1062, "Duplicate entry 'tools-
station' for key 'app_label'")

after some debugging i've found what seems to be an inconsistency in
the contentstype package. it appears to read the django_content_type
from one database (and not find it) and then try to insert a new
record into the 'default' database which already has the record. i
inserted a using('default') into the management.py on all the
ContentTypes.objects calls and all works fine, all ContentTypes the go
into the 'default' database. (i tried using the kwargs['db'] parameter
in the using(), but i got a django_content_type table doesn't exist
error). my question is, is this correct behavior? or are the
ContentTypes for the other 'data' databases supposed to be in the
database where the object resides?

i'm using django 1.2.5 and python 2.7.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment