mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-09 13:14:44 +00:00
* Remove system check for Django version * Closes #175 * Bump version and amend CHANGELOG * Update with GitHub action CI * Update README with Python and Django versions * Limit Django version to 3.2, inclusively. * Add note on Django constraints to README * Bump minor version * Justified by dropping support for dependency versions * Drop support for Django 2.0-2.1, Python 3.5 * Change CI badge in README to GitHub actions * Add support for Pymemcache for Django 3.2+ * Add Django 3.2 to test matrix * Fix MySQL test_explain * Allow filebased delta leniency in tests * Allow Subquery in finding more Subqueries (Fixes #156) * Reverts #157 with proper fix. The initial problem was due to `django.db.models.expressions.Subquery` allowing both QuerySet and sql.Query to be used. * Fixes Django 3.2 test_subquery and test_invalidate_subquery testing by also checking the lhs * Fix Django 2.2 Subquery having no query attr * Fix filebased test time delta * Fix test_invalidate_having due to new inner_query * The new inner_query replaces subquery for Django 3.2 where subquery is now a boolean. That's why I initially used that TypeError in _get_tables_from_sql. inner_query looks to be a sql.Query * Add PyMemcacheCache to supported cache backends Co-authored-by: Dominik George <nik@naturalnet.de>
87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
import copyreg
|
|
from django.apps import AppConfig
|
|
from django.conf import settings
|
|
from django.core.checks import register, Tags, Warning, Error
|
|
from cachalot.utils import ITERABLES
|
|
|
|
from .settings import (
|
|
cachalot_settings, SUPPORTED_CACHE_BACKENDS, SUPPORTED_DATABASE_ENGINES,
|
|
SUPPORTED_ONLY)
|
|
|
|
|
|
@register(Tags.caches, Tags.compatibility)
|
|
def check_cache_compatibility(app_configs, **kwargs):
|
|
cache = settings.CACHES[cachalot_settings.CACHALOT_CACHE]
|
|
cache_backend = cache['BACKEND']
|
|
if cache_backend not in SUPPORTED_CACHE_BACKENDS:
|
|
return [Warning(
|
|
'Cache backend %r is not supported by django-cachalot.'
|
|
% cache_backend,
|
|
hint='Switch to a supported cache backend '
|
|
'like Redis or Memcached.',
|
|
id='cachalot.W001')]
|
|
return []
|
|
|
|
|
|
@register(Tags.database, Tags.compatibility)
|
|
def check_databases_compatibility(app_configs, **kwargs):
|
|
errors = []
|
|
databases = settings.DATABASES
|
|
original_enabled_databases = getattr(settings, 'CACHALOT_DATABASES',
|
|
SUPPORTED_ONLY)
|
|
enabled_databases = cachalot_settings.CACHALOT_DATABASES
|
|
if original_enabled_databases == SUPPORTED_ONLY:
|
|
if not cachalot_settings.CACHALOT_DATABASES:
|
|
errors.append(Warning(
|
|
'None of the configured databases are supported '
|
|
'by django-cachalot.',
|
|
hint='Use a supported database, or remove django-cachalot, or '
|
|
'put at least one database alias in `CACHALOT_DATABASES` '
|
|
'to force django-cachalot to use it.',
|
|
id='cachalot.W002'
|
|
))
|
|
elif enabled_databases.__class__ in ITERABLES:
|
|
for db_alias in enabled_databases:
|
|
if db_alias in databases:
|
|
engine = databases[db_alias]['ENGINE']
|
|
if engine not in SUPPORTED_DATABASE_ENGINES:
|
|
errors.append(Warning(
|
|
'Database engine %r is not supported '
|
|
'by django-cachalot.' % engine,
|
|
hint='Switch to a supported database engine.',
|
|
id='cachalot.W003'
|
|
))
|
|
else:
|
|
errors.append(Error(
|
|
'Database alias %r from `CACHALOT_DATABASES` '
|
|
'is not defined in `DATABASES`.' % db_alias,
|
|
hint='Change `CACHALOT_DATABASES` to be compliant with'
|
|
'`CACHALOT_DATABASES`',
|
|
id='cachalot.E001',
|
|
))
|
|
|
|
if not enabled_databases:
|
|
errors.append(Warning(
|
|
'Django-cachalot is useless because no database '
|
|
'is configured in `CACHALOT_DATABASES`.',
|
|
hint='Reconfigure django-cachalot or remove it.',
|
|
id='cachalot.W004'
|
|
))
|
|
else:
|
|
errors.append(Error(
|
|
"`CACHALOT_DATABASES` must be either %r or a list, tuple, "
|
|
"frozenset or set of database aliases." % SUPPORTED_ONLY,
|
|
hint='Remove `CACHALOT_DATABASES` or change it.',
|
|
id='cachalot.E002',
|
|
))
|
|
return errors
|
|
|
|
|
|
class CachalotConfig(AppConfig):
|
|
name = 'cachalot'
|
|
|
|
def ready(self):
|
|
# Cast memoryview objects to bytes to be able to pickle them.
|
|
# https://docs.python.org/3/library/copyreg.html#copyreg.pickle
|
|
copyreg.pickle(memoryview, lambda val: (memoryview, (bytes(val),)))
|
|
cachalot_settings.load()
|