Exemplo n.º 1
0
async def test_local_cleanup():
    """
    Tests that local cleans up dead threads and tasks
    """
    # Set up the local
    test_local = Local()
    # Assign in a thread
    class TestThread(threading.Thread):
        def run(self):
            test_local.foo = 456

    thread = TestThread()
    thread.start()
    thread.join()
    # Assign in a Task
    async def test_task():
        test_local.foo = 456

    test_future = asyncio.ensure_future(test_task())
    await test_future
    # Check there are two things in the storage
    assert len(test_local._storage) == 2
    # Force cleanup
    test_local._last_cleanup = 0
    test_local.foo = 1
    # There should now only be one thing (this task) in the storage
    assert len(test_local._storage) == 1
Exemplo n.º 2
0
async def test_local_many_layers():
    """
    Tests that local carries through a lot of layers of sync/async
    """
    # Set up the local
    test_local = Local()
    test_local.foo = 8374

    # Make sure we go between each world at least twice
    def sync_function():
        async def async_function():
            def sync_function_2():
                async def async_function_2():
                    assert test_local.foo == 8374
                    test_local.foo = "miracles"

                async_to_sync(async_function_2)()

            await sync_to_async(sync_function_2)()

        async_to_sync(async_function)()

    await sync_to_async(sync_function)()
    # Check the value passed out again
    assert test_local.foo == "miracles"
Exemplo n.º 3
0
def clear_cache_handlers(**kwargs):
    if kwargs["setting"] == "CACHES":
        from django.core.cache import caches, close_caches

        close_caches()
        caches._settings = caches.settings = caches.configure_settings(None)
        caches._connections = Local()
Exemplo n.º 4
0
def language_changed(**kwargs):
    if kwargs['setting'] in {'LANGUAGES', 'LANGUAGE_CODE', 'LOCALE_PATHS'}:
        from django.utils.translation import trans_real
        trans_real._default = None
        trans_real._active = Local()
    if kwargs['setting'] in {'LANGUAGES', 'LOCALE_PATHS'}:
        from django.utils.translation import trans_real
        trans_real._translations = {}
        trans_real.check_for_language.cache_clear()
Exemplo n.º 5
0
def translation_file_changed(sender, file_path, **kwargs):
    """Clear the internal translations cache if a .mo file is modified."""
    if file_path.suffix == '.mo':
        import gettext
        from django.utils.translation import trans_real
        gettext._translations = {}
        trans_real._translations = {}
        trans_real._default = None
        trans_real._active = Local()
        return True
Exemplo n.º 6
0
    def test_template_tags_pgettext(self):
        """{% translate %} takes message contexts into account (#14806)."""
        trans_real._active = Local()
        trans_real._translations = {}
        with translation.override("de"):
            # Nonexistent context...
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "nonexistent" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, "May")

            # Existing context... using a literal
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "month name" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, "Mai")
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "verb" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, "Kann")

            # Using a variable
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context %}')
            rendered = t.render(Context({"message_context": "month name"}))
            self.assertEqual(rendered, "Mai")
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context %}')
            rendered = t.render(Context({"message_context": "verb"}))
            self.assertEqual(rendered, "Kann")

            # Using a filter
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context|lower %}'
            )
            rendered = t.render(Context({"message_context": "MONTH NAME"}))
            self.assertEqual(rendered, "Mai")
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context|lower %}'
            )
            rendered = t.render(Context({"message_context": "VERB"}))
            self.assertEqual(rendered, "Kann")

            # Using 'as'
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "month name" as var %}'
                "Value: {{ var }}")
            rendered = t.render(Context())
            self.assertEqual(rendered, "Value: Mai")
            t = self.get_template(
                '{% load i18n %}{% translate "May" as var context "verb" %}Value: '
                "{{ var }}")
            rendered = t.render(Context())
            self.assertEqual(rendered, "Value: Kann")
Exemplo n.º 7
0
def language_changed(*, setting, **kwargs):
    if setting in {"LANGUAGES", "LANGUAGE_CODE", "LOCALE_PATHS"}:
        from django.utils.translation import trans_real

        trans_real._default = None
        trans_real._active = Local()
    if setting in {"LANGUAGES", "LOCALE_PATHS"}:
        from django.utils.translation import trans_real

        trans_real._translations = {}
        trans_real.check_for_language.cache_clear()
Exemplo n.º 8
0
    def test_template_tags_pgettext(self):
        """{% translate %} takes message contexts into account (#14806)."""
        trans_real._active = Local()
        trans_real._translations = {}
        with translation.override('de'):
            # Nonexistent context...
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "nonexistent" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'May')

            # Existing context... using a literal
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "month name" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Mai')
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "verb" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Kann')

            # Using a variable
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context %}')
            rendered = t.render(Context({'message_context': 'month name'}))
            self.assertEqual(rendered, 'Mai')
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context %}')
            rendered = t.render(Context({'message_context': 'verb'}))
            self.assertEqual(rendered, 'Kann')

            # Using a filter
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context|lower %}'
            )
            rendered = t.render(Context({'message_context': 'MONTH NAME'}))
            self.assertEqual(rendered, 'Mai')
            t = self.get_template(
                '{% load i18n %}{% translate "May" context message_context|lower %}'
            )
            rendered = t.render(Context({'message_context': 'VERB'}))
            self.assertEqual(rendered, 'Kann')

            # Using 'as'
            t = self.get_template(
                '{% load i18n %}{% translate "May" context "month name" as var %}Value: {{ var }}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Value: Mai')
            t = self.get_template(
                '{% load i18n %}{% translate "May" as var context "verb" %}Value: {{ var }}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Value: Kann')
Exemplo n.º 9
0
 def __init__(self, databases=None):
     """
     databases is an optional dictionary of database definitions (structured
     like settings.DATABASES).
     """
     self._databases = databases
     # Connections needs to still be an actual thread local, as it's truly
     # thread-critical. Database backends should use @async_unsafe to protect
     # their code from async contexts, but this will give those contexts
     # separate connections in case it's needed as well. There's no cleanup
     # after async contexts, though, so we don't allow that if we can help it.
     self._connections = Local(thread_critical=True)
Exemplo n.º 10
0
def test_local_thread_to_async():
    """
    Tests that local carries through async_to_sync
    """
    # Set up the local
    test_local = Local()
    test_local.foo = 12
    # Look at it in an async context
    async def async_function():
        assert test_local.foo == 12
        test_local.foo = "inside"

    async_to_sync(async_function)()
    # Check the value passed out again
    assert test_local.foo == "inside"
Exemplo n.º 11
0
def test_local_del_swallows_type_error(monkeypatch):
    test_local = Local()

    blow_up_calls = 0

    def blow_up(self):
        nonlocal blow_up_calls
        blow_up_calls += 1
        raise TypeError()

    monkeypatch.setattr("weakref.WeakSet.__iter__", blow_up)

    test_local.__del__()

    assert blow_up_calls == 1
Exemplo n.º 12
0
async def test_local_task_to_sync():
    """
    Tests that local carries through sync_to_async
    """
    # Set up the local
    test_local = Local()
    test_local.foo = 3
    # Look at it in a sync context
    def sync_function():
        assert test_local.foo == 3
        test_local.foo = "phew, done"

    await sync_to_async(sync_function)()
    # Check the value passed out again
    assert test_local.foo == "phew, done"
Exemplo n.º 13
0
async def test_local_threads_and_tasks():
    """
    Tests that local and threads don't interfere with each other.
    """

    test_local = Local()
    test_local.counter = 0

    def sync_function(expected):
        assert test_local.counter == expected
        test_local.counter += 1

    async def async_function(expected):
        assert test_local.counter == expected
        test_local.counter += 1

    await sync_to_async(sync_function)(0)
    assert test_local.counter == 1

    await async_function(1)
    assert test_local.counter == 2

    class TestThread(threading.Thread):
        def run(self):
            with pytest.raises(AttributeError):
                test_local.counter
            test_local.counter = -1

    await sync_to_async(sync_function)(2)
    assert test_local.counter == 3

    threads = [TestThread() for _ in range(5)]
    for thread in threads:
        thread.start()

    threads[0].join()

    await sync_to_async(sync_function)(3)
    assert test_local.counter == 4

    await async_function(4)
    assert test_local.counter == 5

    for thread in threads[1:]:
        thread.join()

    await sync_to_async(sync_function)(5)
    assert test_local.counter == 6
Exemplo n.º 14
0
def test_local_thread():
    """
    Tests that local works just inside a normal thread context
    """

    test_local = Local()
    # Unassigned should be an error
    with pytest.raises(AttributeError):
        test_local.foo
    # Assign and check it persists
    test_local.foo = 2
    assert test_local.foo == 2
    # Delete and check it errors again
    del test_local.foo
    with pytest.raises(AttributeError):
        test_local.foo
Exemplo n.º 15
0
    def request(self, **request):
        # Use a thread/async task context-local variable to guard against a
        # concurrent _created signal from a different thread/task.
        data = Local()
        data.toolbar = None

        def handle_toolbar_created(sender, toolbar=None, **kwargs):
            data.toolbar = toolbar

        DebugToolbar._created.connect(handle_toolbar_created)
        try:
            response = super().request(**request)
        finally:
            DebugToolbar._created.disconnect(handle_toolbar_created)
        response.toolbar = data.toolbar

        return response
Exemplo n.º 16
0
async def test_local_critical_no_task_to_thread():
    """
    Tests that local doesn't go through sync_to_async when the local is set
    as thread-critical.
    """
    # Set up the local
    test_local = Local(thread_critical=True)
    test_local.foo = 86
    # Look at it in a sync context
    def sync_function():
        with pytest.raises(AttributeError):
            test_local.foo
        test_local.foo = "secret"
        assert test_local.foo == "secret"

    await sync_to_async(sync_function)()
    # Check the value outside is not touched
    assert test_local.foo == 86
Exemplo n.º 17
0
 def __init__(self, pattern, urlconf_name, default_kwargs=None, app_name=None, namespace=None):
     self.pattern = pattern
     # urlconf_name is the dotted Python path to the module defining
     # urlpatterns. It may also be an object with an urlpatterns attribute
     # or urlpatterns itself.
     self.urlconf_name = urlconf_name
     self.callback = None
     self.default_kwargs = default_kwargs or {}
     self.namespace = namespace
     self.app_name = app_name
     self._reverse_dict = {}
     self._namespace_dict = {}
     self._app_dict = {}
     # set of dotted paths to all functions and classes that are used in
     # urlpatterns
     self._callback_strs = set()
     self._populated = False
     self._local = Local()
Exemplo n.º 18
0
def test_local_critical_no_thread_to_task():
    """
    Tests that local does not go through async_to_sync when the local is set
    as thread-critical
    """
    # Set up the local
    test_local = Local(thread_critical=True)
    test_local.foo = 89
    # Look at it in an async context
    async def async_function():
        with pytest.raises(AttributeError):
            test_local.foo
        test_local.foo = "numbers"
        assert test_local.foo == "numbers"

    async_to_sync(async_function)()
    # Check the value outside
    assert test_local.foo == 89
Exemplo n.º 19
0
async def test_local_task_to_sync_to_task():
    """
    Tests that local carries through sync_to_async and then back through
    async_to_sync
    """
    # Set up the local
    test_local = Local()
    test_local.foo = 756
    # Look at it in an async context inside a sync context
    def sync_function():
        async def async_function():
            assert test_local.foo == 756
            test_local.foo = "dragons"

        async_to_sync(async_function)()

    await sync_to_async(sync_function)()
    # Check the value passed out again
    assert test_local.foo == "dragons"
Exemplo n.º 20
0
    def f():
        nonlocal matched
        # Involve Local in a cycle
        cycle = [Local()]
        cycle.append(cycle)
        cycle[0].foo = "bar"

        # GC the cycle
        del cycle
        gc.collect()

        # Trigger the local creation outside
        e1.set()
        e2.wait()

        # New Locals should be empty
        matched = len([
            local for local in locals if getattr(local, "foo", None) == "bar"
        ])
Exemplo n.º 21
0
def test_local_cycle():
    """
    Tests that Local can handle cleanup up a cycle to itself
    (Borrowed and modified from the CPython threadlocal tests)
    """

    locals = None
    matched = 0
    e1 = threading.Event()
    e2 = threading.Event()

    def f():
        nonlocal matched
        # Involve Local in a cycle
        cycle = [Local()]
        cycle.append(cycle)
        cycle[0].foo = "bar"

        # GC the cycle
        del cycle
        gc.collect()

        # Trigger the local creation outside
        e1.set()
        e2.wait()

        # New Locals should be empty
        matched = len([
            local for local in locals if getattr(local, "foo", None) == "bar"
        ])

    t = threading.Thread(target=f)
    t.start()
    e1.wait()
    # Creates locals outside of the inner thread
    locals = [Local() for i in range(100)]
    e2.set()
    t.join()

    assert matched == 0
Exemplo n.º 22
0
 def __init__(self,
              pattern,
              urlconf_name,
              default_kwargs=None,
              app_name=None,
              namespace=None):
     # 该属性值是当前模块中定义的 RoutePattern 类的实例,叫「正则模式对象」
     self.pattern = pattern
     # 该属性值是字符串,它指向项目的路由配置模块 'xxx.urls'
     self.urlconf_name = urlconf_name
     self.callback = None
     self.default_kwargs = default_kwargs or {}
     self.namespace = namespace
     self.app_name = app_name
     self._reverse_dict = {}
     self._namespace_dict = {}
     self._app_dict = {}
     # set of dotted paths to all functions and classes that are used in
     # urlpatterns
     self._callback_strs = set()
     self._populated = False
     self._local = Local()
Exemplo n.º 23
0
def test_local_thread_nested():
    """
    Tests that local does not leak across threads
    """

    test_local = Local()
    # Unassigned should be an error
    with pytest.raises(AttributeError):
        test_local.foo
    print("outside ID", Local._get_context_id())
    # Assign and check it does not persist inside the thread
    class TestThread(threading.Thread):
        # Failure reason
        failed = "unknown"

        def run(self):
            print("inside ID", Local._get_context_id())
            # Make sure the attribute is not there
            try:
                test_local.foo
                self.failed = "leak inside"
                return
            except AttributeError:
                pass
            # Check the value is good
            self.failed = "set inside"
            test_local.foo = 123
            assert test_local.foo == 123
            # Binary signal that these tests passed to the outer thread
            self.failed = ""

    test_local.foo = 8
    thread = TestThread()
    thread.start()
    thread.join()
    assert thread.failed == ""
    # Check it didn't leak back out
    assert test_local.foo == 8
Exemplo n.º 24
0
 def __init__(self):
     self._caches = Local()
Exemplo n.º 25
0
    def test_template_tags_pgettext(self):
        """{% blocktranslate %} takes message contexts into account (#14806)."""
        trans_real._active = Local()
        trans_real._translations = {}
        with translation.override('de'):
            # Nonexistent context
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context "nonexistent" %}May'
                '{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'May')

            # Existing context...  using a literal
            t = self.get_template('{% load i18n %}{% blocktranslate context "month name" %}May{% endblocktranslate %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Mai')
            t = self.get_template('{% load i18n %}{% blocktranslate context "verb" %}May{% endblocktranslate %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Kann')

            # Using a variable
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context message_context %}'
                'May{% endblocktranslate %}'
            )
            rendered = t.render(Context({'message_context': 'month name'}))
            self.assertEqual(rendered, 'Mai')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context message_context %}'
                'May{% endblocktranslate %}'
            )
            rendered = t.render(Context({'message_context': 'verb'}))
            self.assertEqual(rendered, 'Kann')

            # Using a filter
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context message_context|lower %}May{% endblocktranslate %}'
            )
            rendered = t.render(Context({'message_context': 'MONTH NAME'}))
            self.assertEqual(rendered, 'Mai')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context message_context|lower %}May{% endblocktranslate %}'
            )
            rendered = t.render(Context({'message_context': 'VERB'}))
            self.assertEqual(rendered, 'Kann')

            # Using 'count'
            t = self.get_template(
                '{% load i18n %}{% blocktranslate count number=1 context "super search" %}'
                '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, '1 Super-Ergebnis')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate count number=2 context "super search" %}{{ number }}'
                ' super result{% plural %}{{ number }} super results{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, '2 Super-Ergebnisse')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context "other super search" count number=1 %}'
                '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, '1 anderen Super-Ergebnis')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context "other super search" count number=2 %}'
                '{{ number }} super result{% plural %}{{ number }} super results{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, '2 andere Super-Ergebnisse')

            # Using 'with'
            t = self.get_template(
                '{% load i18n %}{% blocktranslate with num_comments=5 context "comment count" %}'
                'There are {{ num_comments }} comments{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Es gibt 5 Kommentare')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate with num_comments=5 context "other comment count" %}'
                'There are {{ num_comments }} comments{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Andere: Es gibt 5 Kommentare')

            # Using trimmed
            t = self.get_template(
                '{% load i18n %}{% blocktranslate trimmed %}\n\nThere\n\t are 5  '
                '\n\n   comments\n{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'There are 5 comments')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate with num_comments=5 context "comment count" trimmed %}\n\n'
                'There are  \t\n  \t {{ num_comments }} comments\n\n{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Es gibt 5 Kommentare')
            t = self.get_template(
                '{% load i18n %}{% blocktranslate context "other super search" count number=2 trimmed %}\n'
                '{{ number }} super \n result{% plural %}{{ number }} super results{% endblocktranslate %}'
            )
            rendered = t.render(Context())
            self.assertEqual(rendered, '2 andere Super-Ergebnisse')

            # Misuses
            msg = "Unknown argument for 'blocktranslate' tag: %r."
            with self.assertRaisesMessage(TemplateSyntaxError, msg % 'month="May"'):
                self.get_template(
                    '{% load i18n %}{% blocktranslate context with month="May" %}{{ month }}{% endblocktranslate %}'
                )
            msg = '"context" in %r tag expected exactly one argument.' % 'blocktranslate'
            with self.assertRaisesMessage(TemplateSyntaxError, msg):
                self.get_template('{% load i18n %}{% blocktranslate context %}{% endblocktranslate %}')
            with self.assertRaisesMessage(TemplateSyntaxError, msg):
                self.get_template(
                    '{% load i18n %}{% blocktranslate count number=2 context %}'
                    '{{ number }} super result{% plural %}{{ number }}'
                    ' super results{% endblocktranslate %}'
                )
Exemplo n.º 26
0
from urllib.parse import urlsplit, urlunsplit

from asgiref.local import Local

from django.utils.encoding import iri_to_uri
from django.utils.functional import lazy
from django.utils.translation import override

from .exceptions import NoReverseMatch, Resolver404
from .resolvers import _get_cached_resolver, get_ns_resolver, get_resolver
from .utils import get_callable

# SCRIPT_NAME prefixes for each thread are stored here. If there's no entry for
# the current thread (which is the only one we ever access), it is assumed to
# be empty.
_prefixes = Local()

# Overridden URLconfs for each thread are stored here.
_urlconfs = Local()


def resolve(path, urlconf=None):
    if urlconf is None:
        urlconf = get_urlconf()
    return get_resolver(urlconf).resolve(path)


def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
    if urlconf is None:
        urlconf = get_urlconf()
    resolver = get_resolver(urlconf)
Exemplo n.º 27
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from contextlib import contextmanager

from asgiref.local import Local
from django.utils.translation import get_language, override

_thread_locals = Local()


def notify_items_pre_save(**kwargs):
    return notify_items(signal_type='pre_save', **kwargs)


def notify_items_post_save(**kwargs):
    return notify_items(signal_type='post_save', **kwargs)


def notify_items_pre_delete(**kwargs):
    return notify_items(signal_type='pre_delete', **kwargs)


def notify_items_post_delete(**kwargs):
    return notify_items(signal_type='post_delete', **kwargs)


def notify_items(signal_type, **kwargs):
    """
    Signal endpoint that actually sends knocks whenever an instance is created / saved
    """
Exemplo n.º 28
0
from .payloads import generate_api_call_payload, generate_event_delivery_attempt_payload
from .tracing import opentracing_trace

if TYPE_CHECKING:

    from celery.exceptions import Retry
    from django.http import HttpRequest, HttpResponse

    from ...core.models import EventDeliveryAttempt

logger = logging.getLogger(__name__)
CACHE_TIMEOUT = parse("2 minutes")
BUFFER_KEY = "observability_buffer"
WEBHOOKS_KEY = "observability_webhooks"
_active_webhooks_exists_cache: Dict[str, Tuple[bool, float]] = {}
_context = Local()


@dataclass
class WebhookData:
    id: int
    saleor_domain: str
    target_url: str
    secret_key: Optional[str] = None


def get_buffer_name() -> str:
    return cache.make_key(BUFFER_KEY)


_webhooks_mem_cache: Dict[str, Tuple[List[WebhookData], float]] = {}
Exemplo n.º 29
0
    To be registered with log_registry.register_action.
    """

    label = ""
    message = ""
    comment = ""

    def format_message(self, log_entry):
        return self.message

    def format_comment(self, log_entry):
        return self.comment


_active = Local()


class LogContext:
    """
    Stores data about the environment in which a logged action happens -
    e.g. the active user - to be stored in the log entry for that action.
    """
    def __init__(self, user=None, generate_uuid=True):
        self.user = user
        if generate_uuid:
            self.uuid = uuid.uuid4()
        else:
            self.uuid = None

    def __enter__(self):
Exemplo n.º 30
0
def clear_cache_handlers(**kwargs):
    if kwargs['setting'] == 'CACHES':
        from django.core.cache import caches
        caches._caches = Local()