Opened 5 years ago

Closed 5 years ago

#30487 closed Bug (wontfix)

Using more than 245 functions in CombinedExpressions causes RecursionError.

Reported by: M1ha Shvn Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: recursion function Func
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi.
When I try to concatenate more than 245 values into django.db.models.expressions.CombinedExpression I get RecursionError "RecursionError: maximum recursion depth exceeded".

A simple example to reproduce:

from django.db.models import F
item = F('test')
for i in range(300):
    item += F('test')
print(item)

returns

Traceback (most recent call last):
  File "/usr/lib/python3.7/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 5, in <module>
  File "/home/vagrant/venv/lib/python3.7/site-packages/django/db/models/expressions.py", line 404, in __str__
    return "{} {} {}".format(self.lhs, self.connector, self.rhs)
  File "/home/vagrant/venv/lib/python3.7/site-packages/django/db/models/expressions.py", line 404, in __str__
    return "{} {} {}".format(self.lhs, self.connector, self.rhs)
  File "/home/vagrant/venv/lib/python3.7/site-packages/django/db/models/expressions.py", line 404, in __str__
    return "{} {} {}".format(self.lhs, self.connector, self.rhs)
  [Previous line repeated 244 more times]
RecursionError: maximum recursion depth exceeded

Change History (1)

comment:1 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed
Summary: Using more than 245 functions in CombinedExpressions causes RecursionErrorUsing more than 245 functions in CombinedExpressions causes RecursionError.
Version: 2.1master

Thanks for the report, however CombinedExpression has a recursive "nature" from the very beginning. IMO we will not be able to fix this with current implementation. You can increase a Python's recursion limit locally, e.g.

>>> import sys
>>> sys.setrecursionlimit(2000)
Note: See TracTickets for help on using tickets.
Back to Top