summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPiotr Pawlaczek <info@pawlaczek.pl>2014-11-15 14:45:00 +0100
committerTim Graham <timograham@gmail.com>2014-12-31 09:42:07 -0500
commite11ff3975f69b96521d94417bbe4125f4abb2774 (patch)
tree48ac9eadafd3dfe990b336177d958e82740687a2 /tests
parentf1a22feaa877e4ff655db7014557112274419898 (diff)
[1.7.x] Fixed #23758 -- Allowed more than 5 levels of subqueries
Refactored bump_prefix() to avoid infinite loop and allow more than than 5 subquires by extending the alphabet to use multi-letters. Backport of 41fc1c0b5eac156e200a10233c7c9210a1c0fed8 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/queries/tests.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index f6162508b9..d8bd45e6e5 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -15,6 +15,7 @@ from django.db.models.sql.datastructures import EmptyResultSet
from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import str_prefix, CaptureQueriesContext
from django.utils import six
+from django.utils.six.moves import range
from .models import (
Annotation, Article, Author, Celebrity, Child, Cover, Detail, DumbCategory,
@@ -380,6 +381,25 @@ class Queries1Tests(BaseQuerysetTest):
['<Item: four>']
)
+ def test_avoid_infinite_loop_on_too_many_subqueries(self):
+ x = Tag.objects.filter(pk=1)
+ local_recursion_limit = 127
+ msg = 'Maximum recursion depth exceeded: too many subqueries.'
+ with self.assertRaisesMessage(RuntimeError, msg):
+ for i in six.moves.range(local_recursion_limit * 2):
+ x = Tag.objects.filter(pk__in=x)
+
+ def test_reasonable_number_of_subq_aliases(self):
+ x = Tag.objects.filter(pk=1)
+ for _ in range(20):
+ x = Tag.objects.filter(pk__in=x)
+ self.assertEqual(
+ x.query.subq_aliases, {
+ 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD',
+ 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN',
+ }
+ )
+
def test_heterogeneous_qs_combination(self):
# Combining querysets built on different models should behave in a well-defined
# fashion. We raise an error.