From 24f24d236deddc6bed2bb4025442f7e37a2fcd86 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Thu, 16 Mar 2023 15:00:51 -0400 Subject: [PATCH] cache: Use QuerySetAny for isinstance check. Previously, `QuerySet` does not support isinstance check since it is defined to be generic in django-stubs. In a recent update, such check is possible by using `QuerySetAny`, a non-generic alias of `QuerySet`. Signed-off-by: Zixuan James Li --- requirements/dev.txt | 6 +++--- requirements/prod.txt | 6 +++--- version.py | 2 +- zerver/lib/cache.py | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 2e58996671..42f6adcf54 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -569,9 +569,9 @@ django-stubs==1.15.0 \ --hash=sha256:0bbf9eb172c5b06eccff2d704c7c3906e4a2c6146df8c32ee9f3a51e29265581 \ --hash=sha256:25010658acac0ce4a69211b55dd719fd16dbfe54fcfe5c878d0c8db07bdd5482 # via -r requirements/mypy.in -django-stubs-ext==0.7.0 \ - --hash=sha256:4fd8cdbc68d1a421f21bb7e0d9e76d50f6a4b504d350ba786405daf536e90c21 \ - --hash=sha256:d729fbc7fe8970a7e26b35956c35b48502516f011d523c0577bdfb02ed956284 +django-stubs-ext==0.8.0 \ + --hash=sha256:9a9ba9e2808737949de96a0fce8b054f12d38e461011d77ebc074ffe8c43dfcb \ + --hash=sha256:a454d349d19c26d6c50c4c6dbc1e8af4a9cda4ce1dc4104e3dd4c0330510cc56 # via # -r requirements/common.in # django-stubs diff --git a/requirements/prod.txt b/requirements/prod.txt index 3e4c3a39d7..80d7810a0e 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -400,9 +400,9 @@ django-statsd-mozilla==0.4.0 \ --hash=sha256:0d87cb63de8107279cbb748caad9aa74c6a44e7e96ccc5dbf07b89f77285a4b8 \ --hash=sha256:81084f3d426f5184f0a0f1dbfe035cc26b66f041d2184559d916a228d856f0d3 # via -r requirements/common.in -django-stubs-ext==0.7.0 \ - --hash=sha256:4fd8cdbc68d1a421f21bb7e0d9e76d50f6a4b504d350ba786405daf536e90c21 \ - --hash=sha256:d729fbc7fe8970a7e26b35956c35b48502516f011d523c0577bdfb02ed956284 +django-stubs-ext==0.8.0 \ + --hash=sha256:9a9ba9e2808737949de96a0fce8b054f12d38e461011d77ebc074ffe8c43dfcb \ + --hash=sha256:a454d349d19c26d6c50c4c6dbc1e8af4a9cda4ce1dc4104e3dd4c0330510cc56 # via -r requirements/common.in django-two-factor-auth[call,phonenumberslite,sms]==1.15.0 \ --hash=sha256:def6b3242cbc53476c06972f1ba5069edd89a94edeb0f2723a6536ff4002dae0 \ diff --git a/version.py b/version.py index f7f7f84405..ca8558fe8f 100644 --- a/version.py +++ b/version.py @@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 169 # historical commits sharing the same major version, in which case a # minor version bump suffices. -PROVISION_VERSION = (224, 3) +PROVISION_VERSION = (224, 4) diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 7bb040a9c2..85cf69561b 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -25,8 +25,9 @@ from typing import ( 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, QuerySet +from django.db.models import Q from django.http import HttpRequest +from django_stubs_ext import QuerySetAny from typing_extensions import ParamSpec from zerver.lib.utils import make_safe_digest, statsd, statsd_key @@ -167,7 +168,7 @@ 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 + if isinstance(val, QuerySetAny): logging.error( "cache_with_key attempted to store a full QuerySet object -- declining to cache", stack_info=True,