diff --git a/cacheops/getset.py b/cacheops/getset.py index d6c567ac..e7d127e7 100644 --- a/cacheops/getset.py +++ b/cacheops/getset.py @@ -142,5 +142,5 @@ def _conj_cache_key(table, conj): for conj in disj] def dnfs_to_schemes(cond_dnfs): - return {table: [",".join(sorted(conj)) for conj in disj] + return {table: list({",".join(sorted(conj)) for conj in disj}) for table, disj in cond_dnfs.items() if disj} diff --git a/tests/tests.py b/tests/tests.py index c5ffd7b5..58127d32 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,4 +1,6 @@ from contextlib import contextmanager +from functools import reduce +import operator import re import platform import unittest @@ -718,6 +720,19 @@ def test_430_no_error_raises(self): # no error raises on delete media_type.delete() + def test_480(self): + orm_lookups = ['title__icontains', 'category__title__icontains', ] + search_terms = ['1', "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"] + queryset = Post.objects.filter(visible=True) + conditions = [] + for search_term in search_terms: + queries = [ + models.Q(**{orm_lookup: search_term}) + for orm_lookup in orm_lookups + ] + conditions.append(reduce(operator.or_, queries)) + list(queryset.filter(reduce(operator.and_, conditions)).cache()) + class RelatedTests(BaseTestCase): fixtures = ['basic']