Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
cache: Log a warning when attempting to store a whole QuerySet.
Alex Vandiverc328de33721f
diff --git a/zerver/lib/cache.py b/zerver/lib/cache.pyindex 7cafb56049f..063019c4c4f 100644--- a/zerver/lib/cache.py+++ b/zerver/lib/cache.py@@ -26,6 +26,7 @@ from django.conf import settingsfrom django.core.cache import cachesfrom django.core.cache.backends.base import BaseCachefrom django.db.models import Q+from django.db.models.query import QuerySetfrom django.http import HttpRequestfrom typing_extensions import ParamSpec@@ -173,6 +174,12 @@ def cache_with_key(return val[0]val = func(*args, **kwargs)+ if isinstance(val, QuerySet): # type: ignore[misc] # https://github.com/typeddjango/django-stubs/issues/704+ logging.warning(+ "cache_with_key attempted to store a full QuerySet object -- flattening using list()",+ stack_info=True,+ )+ val = list(val)cache_set(key, val, cache_name=cache_name, timeout=timeout)