mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[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 41fc1c0b5e from master
This commit is contained in:
committed by
Tim Graham
parent
f1a22feaa8
commit
e11ff3975f
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user