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

Allow custom databases #247

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cachalot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ def check_databases_compatibility(app_configs, **kwargs):
for db_alias in enabled_databases:
if db_alias in databases:
engine = databases[db_alias]['ENGINE']
if engine not in SUPPORTED_DATABASE_ENGINES:
if (
engine not in SUPPORTED_DATABASE_ENGINES
and engine
not in cachalot_settings.CACHALOT_ADDITIONAL_SUPPORTED_DATABASES
and not cachalot_settings.CACHALOT_USE_UNSUPPORTED_DATABASE
):
errors.append(Warning(
'Database engine %r is not supported '
'by django-cachalot.' % engine,
hint='Switch to a supported database engine.',
hint='Switch to a supported database engine, '
'add an entry in `CACHALOT_ADDITIONAL_SUPPORTED_DATABASES`'
', or set True to `CACHALOT_USE_UNSUPPORTED_DATABASE`.',
id='cachalot.W003'
))
else:
Expand Down
2 changes: 2 additions & 0 deletions cachalot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Settings(object):
CACHALOT_ENABLED = True
CACHALOT_CACHE = 'default'
CACHALOT_DATABASES = 'supported_only'
CACHALOT_USE_UNSUPPORTED_DATABASE = False
CACHALOT_ADDITIONAL_SUPPORTED_DATABASES = {}
CACHALOT_TIMEOUT = None
CACHALOT_CACHE_RANDOM = False
CACHALOT_INVALIDATE_RAW = True
Expand Down
7 changes: 7 additions & 0 deletions cachalot/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def test_databases(self):
SUPPORTED_DATABASE_ENGINES.remove(engine)
with self.settings(CACHALOT_DATABASES=SUPPORTED_ONLY):
self.assert_query_cached(qs, after=1)
with self.settings(CACHALOT_USE_UNSUPPORTED_DATABASE=True):
self.assert_query_cached(qs)

custom_engine = 'custom_engine'
with self.settings(CACHALOT_ADDITIONAL_SUPPORTED_DATABASES={custom_engine}):
self.assert_query_cached(qs)

SUPPORTED_DATABASE_ENGINES.add(engine)
with self.settings(CACHALOT_DATABASES=SUPPORTED_ONLY):
self.assert_query_cached(qs)
Expand Down
16 changes: 16 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ Settings
.. |DATABASES| replace:: ``DATABASES``
.. _DATABASES: https://docs.djangoproject.com/en/dev/ref/settings/#databases

``CACHALOT_USE_UNSUPPORTED_DATABASE``
~~~~~~~~~~~~~~~~~~~~~~

:Default: ``False``
:Description:
Whether to allow usage of unsupported databases.
No startup errors will be thrown if this set to `True`.

``CACHALOT_ADDITIONAL_SUPPORTED_DATABASES``
~~~~~~~~~~~~~~~~~~~~~~

:Default: ``frozenset()``
:Description:
Allows us to define custom supported databases without setting
``CACHALOT_USE_UNSUPPORTED_DATABASE`` to ``True``.

``CACHALOT_TIMEOUT``
~~~~~~~~~~~~~~~~~~~~

Expand Down
Loading