Skip to content

Commit c134ad9

Browse files
authored
fix of rethinkdb connection error in ldap mode
1 parent 908052a commit c134ad9

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

mlp/webui.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -510,24 +510,34 @@ async def api_emails():
510510

511511
# Handle appending .filter() to `_sm` for each filter key in `frm`
512512
_sm = await _process_filters(1, r_q=r_q, query=_sm, frm=frm)
513+
try:
514+
_sm, res = await _paginate_query(_sm, frm, rt_conn=conn, rt_query=r_q, order_by=order_by, order_dir=order_dir)
515+
#print(settings.max_limit)
516+
#print(_sm)
517+
_sm = await _sm.limit(settings.max_limit).run(conn, array_limit=settings.rethink_arr_limit)
513518

514-
_sm, res = await _paginate_query(_sm, frm, rt_conn=conn, rt_query=r_q, order_by=order_by, order_dir=order_dir)
515-
#print(settings.max_limit)
516-
#print(_sm)
517-
_sm = await _sm.limit(settings.max_limit).run(conn, array_limit=settings.rethink_arr_limit)
519+
#print(list(_sm))
518520

519-
#print(list(_sm))
521+
sm = []
522+
if type(_sm) is list:
523+
sm = list(_sm)
524+
else:
525+
async for s in _sm:
526+
sm.append(dict(s))
520527

521-
sm = []
522-
if type(_sm) is list:
523-
sm = list(_sm)
524-
else:
525-
async for s in _sm:
526-
sm.append(dict(s))
527-
528-
res.result = sm
528+
res.result = sm
529529

530-
return jsonify(res.to_json_dict())
530+
return jsonify(res.to_json_dict())
531+
532+
except:
533+
#This is acceptable at the moment since that's the normal behavior for every management script
534+
print("Cannot connect to rethinkdb, trying to reconnect!")
535+
__STORE.clear()
536+
r, conn, r_q = await get_rethink()
537+
session['NOTIE_MESSAGE'] = "api_error"
538+
return redirect(f'{PREFIX}/')
539+
#conn.reconnect(noreply_wait=True)
540+
#sys.exit(1)
531541

532542

533543
async def _paginate_query(query: QueryOrTable, frm: Mapping, rt_conn: DefaultConnection, rt_query: rethinkdb.query,

0 commit comments

Comments
 (0)