I currently am stumped as to why I'm gettign the recursion error from the title with the code down below. This error only comes up if either of the for loops are hit (under if ops and if compliance) before the call to results = results.all().
@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)
Oddly enough, the code for some reason works with one name, but no others. If you need any other information, I'm happy to supply it, thank you!
resultsand modifyingresultswithin the loop. I'm not certain that this causes the error you're getting, but it isn't very efficient. A better approach might be to loop overresultsand collect the ids that you want to filter out in a list, then do something likeresults = results.filter(not_(Envelope.envelope_id.in_(list_of_unwanted_ids)))(you may have to importnot_from sqlalchemy).