diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 0e54a88628..b99f03cd88 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -894,7 +894,7 @@ class Query(BaseExpression): self.alias_prefix = prefix break if pos > local_recursion_limit: - raise RuntimeError( + raise RecursionError( 'Maximum recursion depth exceeded: too many subqueries.' ) self.subq_aliases = self.subq_aliases.union([self.alias_prefix]) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 5c4e288b2a..bce514c0bf 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -405,7 +405,7 @@ class Queries1Tests(TestCase): x = Tag.objects.filter(pk=1) local_recursion_limit = sys.getrecursionlimit() // 16 msg = 'Maximum recursion depth exceeded: too many subqueries.' - with self.assertRaisesMessage(RuntimeError, msg): + with self.assertRaisesMessage(RecursionError, msg): for i in range(local_recursion_limit + 2): x = Tag.objects.filter(pk__in=x)