Skip to content

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

Disable Django CacheKeyWarning (#16559)

Marcin Wcisło64d413d87b7e
diff --git a/saleor/settings.py b/saleor/settings.py
index 1eaeca702e..1cc71192db 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -16,6 +16,7 @@ import sentry_sdk
import sentry_sdk.utils
from celery.schedules import crontab
from django.conf import global_settings
+from django.core.cache import CacheKeyWarning
from django.core.exceptions import ImproperlyConfigured
from django.core.management.utils import get_random_secret_key
from django.core.validators import URLValidator
@@ -988,3 +989,8 @@ ENABLE_LIMITING_WEBHOOKS_FOR_IDENTICAL_PAYLOADS = get_bool_from_env(
# Transaction items limit for PaymentGatewayInitialize / TransactionInitialize.
# That setting limits the allowed number of transaction items for single entity.
TRANSACTION_ITEMS_LIMIT = 100
+
+
+# Disable Django warnings regarding too long cache keys being incompatible with
+# memcached to avoid leaking key values.
+warnings.filterwarnings("ignore", category=CacheKeyWarning)
diff --git a/saleor/tests/test_cache_key_warning.py b/saleor/tests/test_cache_key_warning.py
new file mode 100644
index 0000000000..682d54f621
--- /dev/null
+++ b/saleor/tests/test_cache_key_warning.py
@@ -0,0 +1,16 @@
+import warnings
+
+from django.core.cache import CacheKeyWarning, cache
+
+
+def test_ignore_cache_key_warning():
+ key_over_250_characters = 300 * "x"
+
+ # Ensure all warnings are errors
+ warnings.simplefilter("error")
+
+ # Ignore CacheKeyWarning
+ warnings.filterwarnings("ignore", category=CacheKeyWarning)
+
+ # Call a function that throws warning
+ cache.set(key_over_250_characters, "bar")