Skip to content

armgit / zulip

Public Imported from GitHub
0

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.py
index 7cafb56049f..063019c4c4f 100644
--- a/zerver/lib/cache.py
+++ b/zerver/lib/cache.py
@@ -26,6 +26,7 @@ from django.conf import settings
from django.core.cache import caches
from django.core.cache.backends.base import BaseCache
from django.db.models import Q
+from django.db.models.query import QuerySet
from django.http import HttpRequest
from 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)