Error while benchmarking Django 1.8 with multiple databases

I am moving a Django 1.8 project from one database to a read / write setup. I ran into the problem described in Django bug 23718 but the described work didn't help.

Does anyone face similar issues? The relevant code segments are below:

Router:

class DatabaseRouter(object):

    """Router to handle separation of reads and writes."""

    def db_for_read(self, model, **hints):
        """Reads go to a read replica."""
        return 'read'

    def db_for_write(self, model, **hints):
        """Writes always go to default."""
        return 'default'

    def allow_relation(self, obj1, obj2, **hints):
        """Allow relations bet/n objects in the same DB cluster."""
        db_list = ('default', 'read')
        if obj1._state.db in db_list and obj2._state.db in db_list:
            return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """All models end up in this pool."""
        return True

      

corresponding database settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASS,
        'HOST': DB_WRITE
    },
    'read': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': DB_NAME,
        'USER': DB_USER,
        'PASSWORD': DB_PASS,
        'HOST': DB_READ,
        'TEST': {
            'MIRROR': 'default',
        },
    }
}

DATABASE_ROUTERS = ['my_project.routers.DatabaseRouter']

      

work on test replication check:

class ReplicationTestCase(TestCase):

    @classmethod
    def setUpClass(cls):
        super(ReplicationTestCase, cls).setUpClass()
        connections['read']._orig_cursor = connections['read'].cursor
        connections['read'].cursor = connections['default'].cursor

    @classmethod
    def tearDownClass(cls):
        connections['read'].cursor = connections['read']._orig_cursor
        super(ReplicationTestCase, cls).tearDownClass()

      

Anything pop out? I am happy to provide stacktraces from our test environment if helpful. Thank you!

+3
python django database-mirroring


source to share


No one has answered this question yet

Check out similar questions:

588
How do I check multiple variables for a value?
74
How to deal with the lack of foreign key support across databases in Django
6
Python Peewee execute_sql () example
4
Radio buttons in django admin
3
Django-Rest-Framework - how to serialize a request from an unbound model as a nested serializer
2
django dynamic (multiple) databases
0
Separate mongoengine models in django 1.7
0
How do I select a database in a custom django db collection query?
0
Django 1.8 migration error with postgres
0
django-admin dbshell CommandError: You don't seem to have the "sqlite3" program installed or in your path



All Articles
Loading...
X
Show
Funny
Dev
Pics