From 64650340b6390f119cd04bb5e98824e760fa0fbe Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Sun, 4 Oct 2015 23:07:52 +0200 Subject: [PATCH] Checks that the database and the cache are compatible. --- cachalot/apps.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cachalot/apps.py b/cachalot/apps.py index 8efc520..7e19ef1 100644 --- a/cachalot/apps.py +++ b/cachalot/apps.py @@ -1,8 +1,45 @@ from django.apps import AppConfig +from django.conf import settings +from django.core.checks import register, Tags, Error, Warning from .monkey_patch import patch +VALID_DATABASE_ENGINES = { + 'django.db.backends.sqlite3', + 'django.db.backends.postgresql_psycopg2', + 'django.db.backends.mysql', +} + + +VALID_CACHE_BACKENDS = { + 'django.core.cache.backends.locmem.LocMemCache', + 'django.core.cache.backends.filebased.FileBasedCache', + 'django_redis.cache.RedisCache', + 'django.core.cache.backends.memcached.MemcachedCache', + 'django.core.cache.backends.memcached.PyLibMCCache', +} + + +@register(Tags.compatibility) +def check_compatibility(app_configs, **kwargs): + errors = [] + for setting, k, valid_values in ( + (settings.DATABASES, 'ENGINE', VALID_DATABASE_ENGINES), + (settings.CACHES, 'BACKEND', VALID_CACHE_BACKENDS)): + for alias, d in setting.items(): + value = d[k] + if value not in valid_values: + error_class = Error if alias == 'default' else Warning + errors.append( + error_class( + '`%s` is not compatible with django-cachalot.' % value, + id='cachalot.E001', + ) + ) + return errors + + class CachalotConfig(AppConfig): name = 'cachalot' patched = False