Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Warn when locmem cache is used with cached sessions

Patryk Zawadzki8b6c8854c811
diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py
index 5c3cdf49c9..dcaf749f35 100644
--- a/saleor/core/__init__.py
+++ b/saleor/core/__init__.py
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
from babel.numbers import get_territory_currencies
from django.conf import settings
+from django.core.checks import register, Tags, Warning
from django_countries import countries
from django_countries.fields import Country
from geolite2 import geolite2
@@ -27,3 +28,19 @@ def get_currency_for_country(country):
if main_currency in settings.AVAILABLE_CURRENCIES:
return main_currency
return settings.DEFAULT_CURRENCY
+
+
+@register(Tags.caches)
+def my_check(app_configs, **kwargs):
+ errors = []
+ cached_engines = {
+ 'django.contrib.sessions.backends.cache',
+ 'django.contrib.sessions.backends.cached_db'}
+ if ('locmem' in settings.CACHES['default']['BACKEND'] and
+ settings.SESSION_ENGINE in cached_engines):
+ errors.append(
+ Warning(
+ 'Session caching cannot work with locmem backend',
+ 'User sessions need to be globally shared, use a cache server like Redis.',
+ 'saleor.W001'))
+ return errors