Commit b02f08e0 authored by Tom Christie's avatar Tom Christie Committed by Tim Graham
Browse files

Fixed #25034 -- Converted caches ImproperlyConfigured error to a system check.

parent f33b3ebd
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ from django.core import signals
from django.core.cache.backends.base import (
    BaseCache, CacheKeyWarning, InvalidCacheBackendError,
)
from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_string

__all__ = [
@@ -29,9 +28,6 @@ __all__ = [

DEFAULT_CACHE_ALIAS = 'default'

if DEFAULT_CACHE_ALIAS not in settings.CACHES:
    raise ImproperlyConfigured("You must define a '%s' cache" % DEFAULT_CACHE_ALIAS)


def _create_cache(backend, **kwargs):
    try:
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ from .messages import (
from .registry import Tags, register, run_checks, tag_exists

# Import these to force registration of checks
import django.core.checks.caches  # NOQA isort:skip
import django.core.checks.compatibility.django_1_8_0  # NOQA isort:skip
import django.core.checks.model_checks  # NOQA isort:skip
import django.core.checks.security.base  # NOQA isort:skip
+18 −0
Original line number Diff line number Diff line
from __future__ import unicode_literals

from django.conf import settings
from django.core.cache import DEFAULT_CACHE_ALIAS

from . import Error, Tags, register

E001 = Error(
    "You must define a '%s' cache in your CACHES setting." % DEFAULT_CACHE_ALIAS,
    id='caches.E001',
)


@register(Tags.caches)
def check_default_cache_is_configured(app_configs, **kwargs):
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
        return [E001]
    return []
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ class Tags(object):
    Built-in tags for internal checks.
    """
    admin = 'admin'
    caches = 'caches'
    compatibility = 'compatibility'
    models = 'models'
    security = 'security'
+10 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ Django's system checks are organized using the following tags:
* ``compatibility``: Flagging potential problems with version upgrades.
* ``security``: Checks security related configuration.
* ``templates``: Checks template related configuration.
* ``caches``: Checks cache related configuration.

Some checks may be registered with multiple tags.

@@ -569,3 +570,12 @@ configured:
* **templates.E001**: You have ``'APP_DIRS': True`` in your
  :setting:`TEMPLATES` but also specify ``'loaders'`` in ``OPTIONS``. Either
  remove ``APP_DIRS`` or remove the ``'loaders'`` option.

Caches
------

The following checks verify that your :setting:`CACHES` setting is correctly
configured:

* **caches.E001**: You must define a ``'default'`` cache in your
  :setting:`CACHES` setting.
Loading