gpt4 book ai didi

python - SQLAlchemy 递归错误 : maximum recursion depth exceeded while calling a Python object

转载 作者:行者123 更新时间:2023-12-05 07:29:08 31 4
gpt4 key购买 nike

我目前对为什么我使用下面的代码从标题中得到递归错误感到困惑。只有在调用 results = results.all() 之前命中任一 for 循环(在 if ops 和 if compliance 下)时才会出现此错误。

@main.route('/search_results', methods=['GET', 'POST'])
@login_required
def search_results():
""" Here we make the search request and then display the results. We bring in
the params via the url, then use whooshalchemy to search fields we marked
with __searchable__ in the model. If advanced search is selected, we then filter
the results before we display. Note that there are two separate searches for the
separate data types. """
subject = request.args.get('subject')
search_type = request.args.get('search_type')
acct_no = request.args.get('acct_no')
id_ = request.args.get('id_')
rep = request.args.get('rep')
ops = request.args.get('ops')
compliance = request.args.get('compliance')
results = []

...

else:
results = db.session.query(Envelope)
if subject is not None and subject is not '':
results = results.filter(Envelope.subject.like('%'+subject+'%'))
if acct_no is not None and acct_no is not '':
results = results.filter_by(acct_no=acct_no)
if id_ is not None and id_ is not None:
id_ = int(id_)
results = results.filter_by(envelope_id=id_)
if rep is not None and rep is not '' :
results = results.filter_by(initiator=rep)
if ops is not None and ops is not '':
ops_name = external_db.get_fullname_from_username(ops)
for result in results:
if db.session.query(Envelope_recipient).filter_by(envelope_id=result.envelope_id,role='Operations',name=ops_name).first() == None:
results = results.filter(Envelope.envelope_id != result.envelope_id)
if compliance is not None and compliance is not '':
compliance_name = external_db.get_fullname_from_username(ops)
for result in results:
if db.session.query(Envelope_recipient).filter_by(envelope_id=result.envelope_id,role='Compliance',name=compliance_name).first() == None:
results = results.filter(Envelope.envelope_id != result.envelope_id)

#results.all() is a list of all esignature.models.Envelope or .Process_item objects
results = results.all()

return render_template('search_results.html', subject=subject,
search_type=search_type, acct_no=acct_no,
id_=id_, rep=rep, ops=ops,
compliance=compliance, results=results)

奇怪的是,出于某种原因,代码只适用于一个名称,而不能适用于其他名称。如果您需要任何其他信息,我很乐意提供,谢谢!

最佳答案

您似乎在遍历结果并在循环内修改结果。我不确定这是否会导致您收到错误,但效率不高。更好的方法可能是遍历结果并在列表中收集要过滤掉的 ID,然后执行类似的操作

from sqlalchemy import not_
...
results = db.session.query(Envelope).filter(not_(Envelope.envelope_id.in_(list_of_unwanted_ids)))

关于python - SQLAlchemy 递归错误 : maximum recursion depth exceeded while calling a Python object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52897183/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com