Adds the Python type `long` to the cachable param types.
This commit is contained in:
parent
412f82061e
commit
2d5ad63fbd
|
@ -326,8 +326,9 @@ class ReadTestCase(TestUtilsMixin, TransactionTestCase):
|
|||
self.assert_query_cached(qs, [])
|
||||
|
||||
def test_raw_subquery(self):
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(self.t1__permission.pk,))
|
||||
with self.assertNumQueries(0):
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(self.t1__permission.pk,))
|
||||
qs = Test.objects.filter(permission=raw_sql)
|
||||
self.assert_tables(qs, 'cachalot_test', 'auth_permission')
|
||||
self.assert_query_cached(qs, [self.t1])
|
||||
|
|
|
@ -526,8 +526,9 @@ class WriteTestCase(TestUtilsMixin, TransactionTestCase):
|
|||
|
||||
def test_invalidate_raw_subquery(self):
|
||||
permission = Permission.objects.first()
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(permission.pk,))
|
||||
with self.assertNumQueries(0):
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(permission.pk,))
|
||||
with self.assertNumQueries(1):
|
||||
data1 = list(Test.objects.filter(permission=raw_sql))
|
||||
self.assertListEqual(data1, [])
|
||||
|
@ -552,8 +553,9 @@ class WriteTestCase(TestUtilsMixin, TransactionTestCase):
|
|||
|
||||
def test_invalidate_nested_raw_subquery(self):
|
||||
permission = Permission.objects.first()
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(permission.pk,))
|
||||
with self.assertNumQueries(0):
|
||||
raw_sql = RawSQL('SELECT id FROM auth_permission WHERE id = %s',
|
||||
(permission.pk,))
|
||||
with self.assertNumQueries(1):
|
||||
data1 = list(Test.objects.filter(
|
||||
pk__in=Test.objects.filter(permission=raw_sql)))
|
||||
|
|
|
@ -14,7 +14,7 @@ from django.db.models.sql import Query
|
|||
from django.db.models.sql.where import (
|
||||
ExtraWhere, SubqueryConstraint, WhereNode)
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.six import text_type, binary_type
|
||||
from django.utils.six import text_type, binary_type, PY2
|
||||
|
||||
from .settings import cachalot_settings
|
||||
from .transaction import AtomicCache
|
||||
|
@ -35,6 +35,9 @@ CACHABLE_PARAM_TYPES = {
|
|||
datetime.date, datetime.time, datetime.datetime, datetime.timedelta, UUID,
|
||||
}
|
||||
|
||||
if PY2:
|
||||
CACHABLE_PARAM_TYPES.update(long)
|
||||
|
||||
UNCACHABLE_FUNCS = set()
|
||||
if django_version[:2] >= (1, 9):
|
||||
from django.db.models.functions import Now
|
||||
|
@ -65,7 +68,6 @@ def check_parameter_types(params):
|
|||
elif cl is dict:
|
||||
check_parameter_types(p.items())
|
||||
else:
|
||||
print(params, [text_type(p) for p in params])
|
||||
raise UncachableQuery
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue