Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from 0.6 to 0.9, REPLICA_DATABASE KeyError #49

Open
mikelane opened this issue Mar 14, 2019 · 0 comments
Open

Upgrading from 0.6 to 0.9, REPLICA_DATABASE KeyError #49

mikelane opened this issue Mar 14, 2019 · 0 comments

Comments

@mikelane
Copy link

Everything worked fine with v0.6 and the following:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'HOST': os.getenv('DB_HOST'),
        'NAME': os.getenv('DB_NAME'),
        'USER': os.getenv('DB_USER'),
        'PASSWORD': os.getenv('DB_PASSWORD'),
        'CONN_MAX_AGE': None,
    },
    'readonly': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'HOST': os.getenv('RO_DB_HOST') or os.getenv('DB_HOST'),
        'NAME': os.getenv('RO_DB_NAME') or os.getenv('DB_NAME'),
        'USER': os.getenv('RO_DB_USER') or os.getenv('DB_USER'),
        'PASSWORD': os.getenv('RO_DB_PASSWORD') or os.getenv('DB_PASSWORD'),
        'CONN_MAX_AGE': None,
    },
}
# configure readonly slaves https://github.com/jbalogh/django-multidb-router#masterslaverouter
SLAVE_DATABASES = ['readonly']
DATABASE_ROUTERS = ('multidb.MasterSlaveRouter',)

But with v0.9 and only the following changes:

# configure readonly slaves https://github.com/jbalogh/django-multidb-router#replicarouter
REPLICA_DATABASES = ['readonly']
DATABASE_ROUTERS = ('multidb.ReplicaRouter',)

I get the following error:

.venv/lib/python3.6/site-packages/django/db/models/manager.py:82: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
.venv/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py:565: in get_queryset
    return self._apply_rel_filters(queryset)
.venv/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py:541: in _apply_rel_filters
    db = self._db or router.db_for_read(self.model, instance=self.instance)
.venv/lib/python3.6/site-packages/django/db/utils.py:258: in _route_db
    chosen_db = method(model, **hints)
.venv/lib/python3.6/site-packages/multidb/__init__.py:114: in db_for_read
    return get_replica()
.venv/lib/python3.6/site-packages/multidb/__init__.py:86: in get_replica
    return next(_get_replica_list())
.venv/lib/python3.6/site-packages/multidb/__init__.py:78: in _get_replica_list
    settings.DATABASES[db].get('TEST', {})['MIRROR'] = DEFAULT_DB_ALIAS
E   KeyError: 'readonly'

It looks to me like it isn't finding the database named 'readonly', but this only happens when we change the names as per the deprecation warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant